[PATCH 05/12] Cleanup: avoid memory leak

Dirk Hohndel dirk at hohndel.org
Thu Jan 4 08:50:20 PST 2018


Coverity CID 207731

Signed-off-by: Dirk Hohndel <dirk at hohndel.org>
---
 src/divesystem_idive.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/divesystem_idive.c b/src/divesystem_idive.c
index 46ecb3421620..c3d21bd24170 100644
--- a/src/divesystem_idive.c
+++ b/src/divesystem_idive.c
@@ -477,6 +477,7 @@ divesystem_idive_device_foreach (dc_device_t *abstract, dc_dive_callback_t callb
 				WARNING(abstract->context, "Skipped unreadable dive!");
 				continue;
 			} else {
+				dc_buffer_free(buffer);
 				return rc;
 			}
 		}
@@ -500,8 +501,10 @@ divesystem_idive_device_foreach (dc_device_t *abstract, dc_dive_callback_t callb
 				(idx     ) & 0xFF,
 				(idx >> 8) & 0xFF};
 			rc = divesystem_idive_transfer (device, cmd_sample, sizeof(cmd_sample), packet, commands->sample.size * commands->nsamples, &errcode);
-			if (rc != DC_STATUS_SUCCESS)
+			if (rc != DC_STATUS_SUCCESS) {
+				dc_buffer_free(buffer);
 				return rc;
+			}
 
 			// If the number of samples is not an exact multiple of the
 			// number of samples per packet, then the last packet
-- 
2.15.1



More information about the devel mailing list