Skip to content

Commit

Permalink
Merge pull request #259 from rigomate/fixleaks
Browse files Browse the repository at this point in the history
Fix memory leaks
  • Loading branch information
SciLor authored Nov 20, 2024
2 parents 5817bb7 + 62661a5 commit 7178316
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/handler_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ error_t handleApiFileIndex(HttpConnection *connection, const char_t *uri, const

if (queryPrepare(queryString, &rootPath, overlay, sizeof(overlay), &client_ctx->settings) != NO_ERROR)
{
osFreeMem(jsonString);
return ERROR_FAILURE;
}

Expand Down Expand Up @@ -881,6 +882,7 @@ error_t handleApiFileIndex(HttpConnection *connection, const char_t *uri, const
}

osFreeMem(pathAbsolute);
osFreeMem(jsonString);
jsonString = cJSON_PrintUnformatted(json);
cJSON_Delete(json);
} while (0);
Expand Down
5 changes: 4 additions & 1 deletion src/json_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ cJSON *jsonAddByteArrayToObject(cJSON *const object, const char *const name, uin
sprintf(&string[i * 2], "%02hhx", bytes[i]);
}

return cJSON_AddStringToObject(object, name, string);
// temporary object is needed, so we can free string, because of lack of RAII
cJSON *tmpObject = cJSON_AddStringToObject(object, name, string);
osFreeMem(string);
return tmpObject;
}

bool_t jsonGetBool(cJSON *jsonElement, char *name)
Expand Down
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ void set_settings(const char *option)
{
TRACE_ERROR("Invalid config-set option format. Expected name=value.\r\n");
}
osFreeMem(data);
}

void exit_cleanup(int exit_code)
Expand Down
2 changes: 2 additions & 0 deletions src/tonie_audio_playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ error_t tap_generate_taf(tonie_audio_playlist_t *tap, size_t *current_source, bo
char source[99][PATH_LEN];
if (tap->filesCount == 0)
{
osFreeMem(tmp_taf);
freeTonieInfo(tonieInfo);
return ERROR_INVALID_FILE;
}

Expand Down

0 comments on commit 7178316

Please sign in to comment.