Skip to content

Commit

Permalink
Free keys on error #1373
Browse files Browse the repository at this point in the history
  • Loading branch information
icraggs committed Oct 9, 2023
1 parent 67e3eb6 commit 9fd3e62
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/MQTTPersistenceDefault.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2009, 2020 IBM Corp.
* Copyright (c) 2009, 2023 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
Expand Down Expand Up @@ -835,12 +835,18 @@ int keysUnix(char *dirname, char ***keys, int *nkeys)

if (!temp)
{
int n = 0;
for (n = 0; n < i; n++)
free(fkeys[n]);
free(fkeys);
rc = PAHO_MEMORY_ERROR;
goto exit;
}
if (snprintf(temp, allocsize, "%s/%s", dirname, dir_entry->d_name) >= allocsize)
{
int n = 0;
for (n = 0; n < i; n++)
free(fkeys[n]);
free(temp);
free(fkeys);
rc = MQTTCLIENT_PERSISTENCE_ERROR;
Expand All @@ -850,6 +856,9 @@ int keysUnix(char *dirname, char ***keys, int *nkeys)
{
if ((fkeys[i] = malloc(strlen(dir_entry->d_name) + 1)) == NULL)
{
int n = 0;
for (n = 0; n < i; n++)
free(fkeys[n]);
free(temp);
free(fkeys);
rc = PAHO_MEMORY_ERROR;
Expand Down

0 comments on commit 9fd3e62

Please sign in to comment.