uart drivers: missing uart_close() on some error handling branches
This commit is contained in:
parent
c1372a009f
commit
2e801a62d5
3 changed files with 23 additions and 6 deletions
|
@ -429,6 +429,7 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
|
||||||
nfc_device *pnd = nfc_device_new(context, connstring);
|
nfc_device *pnd = nfc_device_new(context, connstring);
|
||||||
if (!pnd) {
|
if (!pnd) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
|
uart_close(sp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,6 +437,7 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
|
||||||
pnd->driver_data = malloc(sizeof(struct acr122s_data));
|
pnd->driver_data = malloc(sizeof(struct acr122s_data));
|
||||||
if (!pnd->driver_data) {
|
if (!pnd->driver_data) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
|
uart_close(sp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
DRIVER_DATA(pnd)->port = sp;
|
DRIVER_DATA(pnd)->port = sp;
|
||||||
|
@ -443,6 +445,7 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if (pipe(DRIVER_DATA(pnd)->abort_fds) < 0) {
|
if (pipe(DRIVER_DATA(pnd)->abort_fds) < 0) {
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -459,9 +462,9 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
pn53x_data_free(pnd);
|
pn53x_data_free(pnd);
|
||||||
nfc_device_free(pnd);
|
nfc_device_free(pnd);
|
||||||
uart_close(sp);
|
|
||||||
|
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -550,7 +553,7 @@ acr122s_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
if (!pnd) {
|
if (!pnd) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
free(ndd.port);
|
free(ndd.port);
|
||||||
acr122s_close(pnd);
|
uart_close(sp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
pnd->driver = &acr122s_driver;
|
pnd->driver = &acr122s_driver;
|
||||||
|
@ -560,7 +563,8 @@ acr122s_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
pnd->driver_data = malloc(sizeof(struct acr122s_data));
|
pnd->driver_data = malloc(sizeof(struct acr122s_data));
|
||||||
if (!pnd->driver_data) {
|
if (!pnd->driver_data) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
acr122s_close(pnd);
|
uart_close(sp);
|
||||||
|
nfc_device_free(pnd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,7 +573,8 @@ acr122s_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
|
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
if (pipe(DRIVER_DATA(pnd)->abort_fds) < 0) {
|
if (pipe(DRIVER_DATA(pnd)->abort_fds) < 0) {
|
||||||
acr122s_close(pnd);
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
|
nfc_device_free(pnd);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -120,6 +120,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
||||||
nfc_device *pnd = nfc_device_new(context, connstring);
|
nfc_device *pnd = nfc_device_new(context, connstring);
|
||||||
if (!pnd) {
|
if (!pnd) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
|
uart_close(sp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,6 +128,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
||||||
pnd->driver_data = malloc(sizeof(struct arygon_data));
|
pnd->driver_data = malloc(sizeof(struct arygon_data));
|
||||||
if (!pnd->driver_data) {
|
if (!pnd->driver_data) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
|
uart_close(sp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DRIVER_DATA(pnd)->port = sp;
|
DRIVER_DATA(pnd)->port = sp;
|
||||||
|
@ -137,6 +139,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
// pipe-based abort mecanism
|
// pipe-based abort mecanism
|
||||||
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
|
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -144,9 +147,9 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int res = arygon_reset_tama(pnd);
|
int res = arygon_reset_tama(pnd);
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
pn53x_data_free(pnd);
|
pn53x_data_free(pnd);
|
||||||
nfc_device_free(pnd);
|
nfc_device_free(pnd);
|
||||||
uart_close(sp);
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -237,6 +240,7 @@ arygon_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
if (!pnd) {
|
if (!pnd) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
free(ndd.port);
|
free(ndd.port);
|
||||||
|
uart_close(sp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
snprintf(pnd->name, sizeof(pnd->name), "%s:%s", ARYGON_DRIVER_NAME, ndd.port);
|
snprintf(pnd->name, sizeof(pnd->name), "%s:%s", ARYGON_DRIVER_NAME, ndd.port);
|
||||||
|
@ -245,6 +249,7 @@ arygon_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
pnd->driver_data = malloc(sizeof(struct arygon_data));
|
pnd->driver_data = malloc(sizeof(struct arygon_data));
|
||||||
if (!pnd->driver_data) {
|
if (!pnd->driver_data) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
|
uart_close(sp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
DRIVER_DATA(pnd)->port = sp;
|
DRIVER_DATA(pnd)->port = sp;
|
||||||
|
@ -262,6 +267,7 @@ arygon_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
// pipe-based abort mecanism
|
// pipe-based abort mecanism
|
||||||
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
|
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -90,12 +90,14 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
|
||||||
nfc_device *pnd = nfc_device_new(context, connstring);
|
nfc_device *pnd = nfc_device_new(context, connstring);
|
||||||
if (!pnd) {
|
if (!pnd) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
|
uart_close(sp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
pnd->driver = &pn532_uart_driver;
|
pnd->driver = &pn532_uart_driver;
|
||||||
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
|
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
|
||||||
if (!pnd->driver_data) {
|
if (!pnd->driver_data) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
|
uart_close(sp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DRIVER_DATA(pnd)->port = sp;
|
DRIVER_DATA(pnd)->port = sp;
|
||||||
|
@ -110,6 +112,7 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
// pipe-based abort mecanism
|
// pipe-based abort mecanism
|
||||||
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
|
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -118,9 +121,9 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
|
||||||
|
|
||||||
// Check communication using "Diagnose" command, with "Communication test" (0x00)
|
// Check communication using "Diagnose" command, with "Communication test" (0x00)
|
||||||
int res = pn53x_check_communication(pnd);
|
int res = pn53x_check_communication(pnd);
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
pn53x_data_free(pnd);
|
pn53x_data_free(pnd);
|
||||||
nfc_device_free(pnd);
|
nfc_device_free(pnd);
|
||||||
uart_close(sp);
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -209,6 +212,7 @@ pn532_uart_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
if (!pnd) {
|
if (!pnd) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
free(ndd.port);
|
free(ndd.port);
|
||||||
|
uart_close(sp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
snprintf(pnd->name, sizeof(pnd->name), "%s:%s", PN532_UART_DRIVER_NAME, ndd.port);
|
snprintf(pnd->name, sizeof(pnd->name), "%s:%s", PN532_UART_DRIVER_NAME, ndd.port);
|
||||||
|
@ -217,6 +221,7 @@ pn532_uart_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
|
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
|
||||||
if (!pnd->driver_data) {
|
if (!pnd->driver_data) {
|
||||||
perror("malloc");
|
perror("malloc");
|
||||||
|
uart_close(sp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
DRIVER_DATA(pnd)->port = sp;
|
DRIVER_DATA(pnd)->port = sp;
|
||||||
|
@ -235,6 +240,7 @@ pn532_uart_open(const nfc_context *context, const nfc_connstring connstring)
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
// pipe-based abort mecanism
|
// pipe-based abort mecanism
|
||||||
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
|
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
|
||||||
|
uart_close(DRIVER_DATA(pnd)->port);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|
Loading…
Reference in a new issue