mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
fix: double free shouldn't happen now
This commit is contained in:
parent
20e4af5856
commit
08bf63c748
3 changed files with 12 additions and 10 deletions
|
@ -372,11 +372,7 @@ int main(int argc, char* argv[]) {
|
||||||
#else
|
#else
|
||||||
main_loop(script_cmds_file, usb_present);
|
main_loop(script_cmds_file, usb_present);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Clean up the port
|
|
||||||
if (usb_present)
|
|
||||||
uart_close(sp);
|
|
||||||
|
|
||||||
// clean up mutex
|
// clean up mutex
|
||||||
pthread_mutex_destroy(&print_lock);
|
pthread_mutex_destroy(&print_lock);
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ serial_port uart_open(const char* pcPortName)
|
||||||
sp->tiNew.c_cc[VTIME] = 0;
|
sp->tiNew.c_cc[VTIME] = 0;
|
||||||
|
|
||||||
// Try to set the new terminal info struct
|
// Try to set the new terminal info struct
|
||||||
if(tcsetattr(sp->fd,TCSANOW,&sp->tiNew) == -1) {
|
if(tcsetattr(sp->fd, TCSANOW, &sp->tiNew) == -1) {
|
||||||
uart_close(sp);
|
uart_close(sp);
|
||||||
return INVALID_SERIAL_PORT;
|
return INVALID_SERIAL_PORT;
|
||||||
}
|
}
|
||||||
|
@ -128,9 +128,13 @@ serial_port uart_open(const char* pcPortName)
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart_close(const serial_port sp) {
|
void uart_close(const serial_port sp) {
|
||||||
|
if (!sp) return;
|
||||||
|
if (sp == INVALID_SERIAL_PORT) return;
|
||||||
|
if (sp == CLAIMED_SERIAL_PORT) return;
|
||||||
|
|
||||||
serial_port_unix* spu = (serial_port_unix*)sp;
|
serial_port_unix* spu = (serial_port_unix*)sp;
|
||||||
tcflush(spu->fd,TCIOFLUSH);
|
tcflush(spu->fd, TCIOFLUSH);
|
||||||
tcsetattr(spu->fd,TCSANOW,&(spu->tiOld));
|
tcsetattr(spu->fd, TCSANOW, &(spu->tiOld));
|
||||||
struct flock fl;
|
struct flock fl;
|
||||||
fl.l_type = F_UNLCK;
|
fl.l_type = F_UNLCK;
|
||||||
fl.l_whence = SEEK_SET;
|
fl.l_whence = SEEK_SET;
|
||||||
|
|
|
@ -69,7 +69,7 @@ serial_port uart_open(const char* pcPortName) {
|
||||||
sp->hPort = CreateFileA(acPortName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
sp->hPort = CreateFileA(acPortName, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||||
if (sp->hPort == INVALID_HANDLE_VALUE) {
|
if (sp->hPort == INVALID_HANDLE_VALUE) {
|
||||||
uart_close(sp);
|
uart_close(sp);
|
||||||
return INVALID_SERIAL_PORT;
|
return INVALID_SERIAL_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare the device control
|
// Prepare the device control
|
||||||
|
@ -107,7 +107,9 @@ serial_port uart_open(const char* pcPortName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void uart_close(const serial_port sp) {
|
void uart_close(const serial_port sp) {
|
||||||
if (!sp) return;
|
if (!sp) return;
|
||||||
|
if (sp == INVALID_SERIAL_PORT) return;
|
||||||
|
if (sp == CLAIMED_SERIAL_PORT) return;
|
||||||
if (((serial_port_windows*)sp)->hPort != NULL )
|
if (((serial_port_windows*)sp)->hPort != NULL )
|
||||||
CloseHandle(((serial_port_windows*)sp)->hPort);
|
CloseHandle(((serial_port_windows*)sp)->hPort);
|
||||||
free(sp);
|
free(sp);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue