From 2994441d9cd647d6ec06d343d0c41394a79b6613 Mon Sep 17 00:00:00 2001 From: Maxim Biro Date: Mon, 4 Dec 2023 20:31:48 -0500 Subject: [PATCH] Fix memory leak in save-generator --- other/fun/save-generator.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/other/fun/save-generator.c b/other/fun/save-generator.c index 7e8aa344..6f65a959 100644 --- a/other/fun/save-generator.c +++ b/other/fun/save-generator.c @@ -73,10 +73,15 @@ static void print_information(Tox *tox) int length = snprintf(nospam_str, sizeof(nospam_str), "%08X", nospam); nospam_str[length] = '\0'; - uint8_t *name = (uint8_t *)malloc(tox_self_get_name_size(tox) + 1); - assert(name != nullptr); + size_t name_size = tox_self_get_name_size(tox); + uint8_t *name = (uint8_t *)malloc(name_size + 1); + + if (!name) { + return; + } + tox_self_get_name(tox, name); - name[tox_self_get_name_size(tox)] = '\0'; + name[name_size] = '\0'; printf("INFORMATION\n"); printf("----------------------------------\n"); @@ -86,6 +91,8 @@ static void print_information(Tox *tox) printf("Status message: %s.\n", GENERATED_STATUS_MESSAGE); printf("Number of friends: %zu.\n", tox_self_get_friend_list_size(tox)); printf("----------------------------------\n"); + + free(name); } int main(int argc, char *argv[])