From f6154a6d81d29f5b578757a7048752efdc37ca24 Mon Sep 17 00:00:00 2001 From: Lnc Date: Tue, 17 Jun 2014 12:15:06 +0200 Subject: [PATCH] Fix memory leaks from osl_strings_malloc --- source/body.c | 2 -- source/strings.c | 5 ++++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/source/body.c b/source/body.c index f2ed91a..9fc3db5 100644 --- a/source/body.c +++ b/source/body.c @@ -269,8 +269,6 @@ osl_body_p osl_body_sread(char ** input) { } else { body->iterators = osl_strings_malloc(); - OSL_malloc(body->iterators->string, char **, sizeof(char *)); - body->iterators->string[0] = NULL; } // Read the body: diff --git a/source/strings.c b/source/strings.c index 0a4c2bd..f5a519e 100644 --- a/source/strings.c +++ b/source/strings.c @@ -239,6 +239,7 @@ osl_strings_p osl_strings_sread(char ** input) { // Build the strings structure strings = osl_strings_malloc(); + free(strings->string); strings->string = string; } @@ -335,6 +336,7 @@ osl_strings_p osl_strings_clone(osl_strings_p strings) { if ((nb_strings = osl_strings_size(strings)) == 0) return clone; + free(clone->string); OSL_malloc(clone->string, char **, (nb_strings + 1) * sizeof(char *)); clone->string[nb_strings] = NULL; for (i = 0; i < nb_strings; i++) @@ -430,7 +432,7 @@ size_t osl_strings_size(osl_const_strings_const_p strings) { */ osl_strings_p osl_strings_encapsulate(char * string) { osl_strings_p capsule = osl_strings_malloc(); - + free(capsule->string); OSL_malloc(capsule->string, char **, 2 * sizeof(char *)); capsule->string[0] = string; capsule->string[1] = NULL; @@ -488,6 +490,7 @@ osl_strings_p osl_strings_generate(char * prefix, int nb_strings) { } generated = osl_strings_malloc(); + free(generated->string); generated->string = strings; return generated; } -- 2.11.4.GIT