Fix memory leak
Problems reported by Coverity: CID 1090335 (#1 of 1): Resource leak (RESOURCE_LEAK) 24. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to. CID 1090336 (#1 of 1): Resource leak (RESOURCE_LEAK) 10. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to. CID 1090337 (#1 of 1): Resource leak (RESOURCE_LEAK) 21. leaked_storage: Variable "i2cPorts" going out of scope leaks the storage it points to. CID 1090338 (#1 of 1): Resource leak (RESOURCE_LEAK) 21. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to. CID 1090339 (#1 of 1): Resource leak (RESOURCE_LEAK) 23. leaked_storage: Variable "acPorts" going out of scope leaks the storage it points to.
This commit is contained in:
parent
b6b63f10b4
commit
3d040d73f3
5 changed files with 90 additions and 0 deletions
|
@ -435,6 +435,11 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
|
|||
if (!pnd) {
|
||||
perror("malloc");
|
||||
uart_close(sp);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -444,6 +449,11 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
|
|||
perror("malloc");
|
||||
uart_close(sp);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return -1;
|
||||
}
|
||||
DRIVER_DATA(pnd)->port = sp;
|
||||
|
@ -453,6 +463,11 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
|
|||
if (pipe(DRIVER_DATA(pnd)->abort_fds) < 0) {
|
||||
uart_close(DRIVER_DATA(pnd)->port);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
@ -463,6 +478,11 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
|
|||
perror("malloc");
|
||||
uart_close(DRIVER_DATA(pnd)->port);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
CHIP_DATA(pnd)->type = PN532;
|
||||
|
|
|
@ -122,6 +122,11 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
|||
if (!pnd) {
|
||||
perror("malloc");
|
||||
uart_close(sp);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -131,6 +136,11 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
|||
perror("malloc");
|
||||
uart_close(sp);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
DRIVER_DATA(pnd)->port = sp;
|
||||
|
@ -140,6 +150,11 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
|||
perror("malloc");
|
||||
uart_close(DRIVER_DATA(pnd)->port);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -149,6 +164,11 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
|
|||
uart_close(DRIVER_DATA(pnd)->port);
|
||||
pn53x_data_free(pnd);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
|
|
@ -125,6 +125,11 @@ pn532_i2c_scan(const nfc_context *context, nfc_connstring connstrings[], const s
|
|||
if (!pnd) {
|
||||
perror("malloc");
|
||||
i2c_close(id);
|
||||
iDevice = 0;
|
||||
while ((i2cPort = i2cPorts[iDevice++])) {
|
||||
free((void *)i2cPort);
|
||||
}
|
||||
free(i2cPorts);
|
||||
return 0;
|
||||
}
|
||||
pnd->driver = &pn532_i2c_driver;
|
||||
|
@ -133,6 +138,11 @@ pn532_i2c_scan(const nfc_context *context, nfc_connstring connstrings[], const s
|
|||
perror("malloc");
|
||||
i2c_close(id);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((i2cPort = i2cPorts[iDevice++])) {
|
||||
free((void *)i2cPort);
|
||||
}
|
||||
free(i2cPorts);
|
||||
return 0;
|
||||
}
|
||||
DRIVER_DATA(pnd)->dev = id;
|
||||
|
@ -142,6 +152,11 @@ pn532_i2c_scan(const nfc_context *context, nfc_connstring connstrings[], const s
|
|||
perror("malloc");
|
||||
i2c_close(DRIVER_DATA(pnd)->dev);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((i2cPort = i2cPorts[iDevice++])) {
|
||||
free((void *)i2cPort);
|
||||
}
|
||||
free(i2cPorts);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -111,6 +111,11 @@ pn532_spi_scan(const nfc_context *context, nfc_connstring connstrings[], const s
|
|||
if (!pnd) {
|
||||
perror("malloc");
|
||||
spi_close(sp);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
pnd->driver = &pn532_spi_driver;
|
||||
|
@ -119,6 +124,11 @@ pn532_spi_scan(const nfc_context *context, nfc_connstring connstrings[], const s
|
|||
perror("malloc");
|
||||
spi_close(sp);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
DRIVER_DATA(pnd)->port = sp;
|
||||
|
@ -128,6 +138,11 @@ pn532_spi_scan(const nfc_context *context, nfc_connstring connstrings[], const s
|
|||
perror("malloc");
|
||||
spi_close(DRIVER_DATA(pnd)->port);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
// SAMConfiguration command if needed to wakeup the chip and pn53x_SAMConfiguration check if the chip is a PN532
|
||||
|
|
|
@ -96,6 +96,11 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
|
|||
if (!pnd) {
|
||||
perror("malloc");
|
||||
uart_close(sp);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
pnd->driver = &pn532_uart_driver;
|
||||
|
@ -104,6 +109,11 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
|
|||
perror("malloc");
|
||||
uart_close(sp);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
DRIVER_DATA(pnd)->port = sp;
|
||||
|
@ -113,6 +123,11 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
|
|||
perror("malloc");
|
||||
uart_close(DRIVER_DATA(pnd)->port);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
// SAMConfiguration command if needed to wakeup the chip and pn53x_SAMConfiguration check if the chip is a PN532
|
||||
|
@ -126,6 +141,11 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
|
|||
uart_close(DRIVER_DATA(pnd)->port);
|
||||
pn53x_data_free(pnd);
|
||||
nfc_device_free(pnd);
|
||||
iDevice = 0;
|
||||
while ((acPort = acPorts[iDevice++])) {
|
||||
free((void *)acPort);
|
||||
}
|
||||
free(acPorts);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
|
|
Loading…
Add table
Reference in a new issue