From dfbf65cc0f9dfd99650cd38e3edca4ab4fca8e18 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Fri, 15 Jul 2022 19:32:57 +0200 Subject: [PATCH] replaced repeating malloc with realloc tf I tried to fix this much earlier but it was throwing segfaults... I should start taking those pills --- src/lib/decrypter.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lib/decrypter.c b/src/lib/decrypter.c index 01c6909..5ad331a 100644 --- a/src/lib/decrypter.c +++ b/src/lib/decrypter.c @@ -79,7 +79,13 @@ outputFlags decryptText(char *text, char *keyNew) numberBuffer++; } - textBuffer = malloc(numberBuffer + 1); + if (i != 0) + { + textBuffer = realloc(textBuffer, numberBuffer + 1); + } else + { + textBuffer = malloc(numberBuffer + 1); + } //LOAD textBuffer for (int j = 0; j < (int) strlen(text); j++) @@ -92,7 +98,6 @@ outputFlags decryptText(char *text, char *keyNew) encryptedTextKeyChain[i] = atoi(textBuffer); text += numberBuffer + 1; - free(textBuffer); } //DECRYPT TEXT @@ -130,6 +135,7 @@ outputFlags decryptText(char *text, char *keyNew) //DEALLOCATION free(textKeyChain); free(encryptedTextKeyChain); + free(textBuffer); return output; }