Skip to content

Commit 9fd3e62

Browse files
committed
Free keys on error eclipse-paho#1373
1 parent 67e3eb6 commit 9fd3e62

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/MQTTPersistenceDefault.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2020 IBM Corp.
2+
* Copyright (c) 2009, 2023 IBM Corp.
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v2.0
@@ -835,12 +835,18 @@ int keysUnix(char *dirname, char ***keys, int *nkeys)
835835

836836
if (!temp)
837837
{
838+
int n = 0;
839+
for (n = 0; n < i; n++)
840+
free(fkeys[n]);
838841
free(fkeys);
839842
rc = PAHO_MEMORY_ERROR;
840843
goto exit;
841844
}
842845
if (snprintf(temp, allocsize, "%s/%s", dirname, dir_entry->d_name) >= allocsize)
843846
{
847+
int n = 0;
848+
for (n = 0; n < i; n++)
849+
free(fkeys[n]);
844850
free(temp);
845851
free(fkeys);
846852
rc = MQTTCLIENT_PERSISTENCE_ERROR;
@@ -850,6 +856,9 @@ int keysUnix(char *dirname, char ***keys, int *nkeys)
850856
{
851857
if ((fkeys[i] = malloc(strlen(dir_entry->d_name) + 1)) == NULL)
852858
{
859+
int n = 0;
860+
for (n = 0; n < i; n++)
861+
free(fkeys[n]);
853862
free(temp);
854863
free(fkeys);
855864
rc = PAHO_MEMORY_ERROR;

0 commit comments

Comments
 (0)