From 2bc22981fd351a8c4c2b4878781fbea8eb1f55ea Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 21 Jan 2014 21:07:35 +0000 Subject: [PATCH] Fixed memory leaks from str_replace --- src/otr.c | 3 +++ tests/test_common.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/src/otr.c b/src/otr.c index 9ef96f8a..fb8af681 100644 --- a/src/otr.c +++ b/src/otr.c @@ -81,6 +81,7 @@ cb_write_fingerprints(void *opdata) g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); + free(account_dir); GString *fpsfilename = g_string_new(basedir->str); g_string_append(fpsfilename, "fingerprints.txt"); @@ -128,6 +129,7 @@ otr_on_connect(ProfAccount *account) g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); + free(account_dir); if (!mkdir_recursive(basedir->str)) { log_error("Could not create %s for account %s.", basedir->str, jid); @@ -209,6 +211,7 @@ otr_keygen(ProfAccount *account) g_string_append(basedir, "/profanity/otr/"); g_string_append(basedir, account_dir); g_string_append(basedir, "/"); + free(account_dir); if (!mkdir_recursive(basedir->str)) { log_error("Could not create %s for account %s.", basedir->str, jid); diff --git a/tests/test_common.c b/tests/test_common.c index 0d02bbd0..146cb7d0 100644 --- a/tests/test_common.c +++ b/tests/test_common.c @@ -14,6 +14,8 @@ void replace_one_substr(void **state) char *result = str_replace(string, sub, new); assert_string_equal("it was a string", result); + + free(result); } void replace_one_substr_beginning(void **state) @@ -25,6 +27,8 @@ void replace_one_substr_beginning(void **state) char *result = str_replace(string, sub, new); assert_string_equal("that is a string", result); + + free(result); } void replace_one_substr_end(void **state) @@ -36,6 +40,8 @@ void replace_one_substr_end(void **state) char *result = str_replace(string, sub, new); assert_string_equal("it is a thing", result); + + free(result); } void replace_two_substr(void **state) @@ -47,6 +53,8 @@ void replace_two_substr(void **state) char *result = str_replace(string, sub, new); assert_string_equal("it was a was string", result); + + free(result); } void replace_char(void **state) @@ -58,6 +66,8 @@ void replace_char(void **state) char *result = str_replace(string, sub, new); assert_string_equal("some & a thing & something else", result); + + free(result); } void replace_when_none(void **state) @@ -69,6 +79,8 @@ void replace_when_none(void **state) char *result = str_replace(string, sub, new); assert_string_equal("its another string", result); + + free(result); } void replace_when_match(void **state) @@ -80,6 +92,8 @@ void replace_when_match(void **state) char *result = str_replace(string, sub, new); assert_string_equal("goodbye", result); + + free(result); } void replace_when_string_empty(void **state) @@ -91,6 +105,8 @@ void replace_when_string_empty(void **state) char *result = str_replace(string, sub, new); assert_string_equal("", result); + + free(result); } void replace_when_string_null(void **state) @@ -113,6 +129,8 @@ void replace_when_sub_empty(void **state) char *result = str_replace(string, sub, new); assert_string_equal("hello", result); + + free(result); } void replace_when_sub_null(void **state) @@ -124,6 +142,8 @@ void replace_when_sub_null(void **state) char *result = str_replace(string, sub, new); assert_string_equal("hello", result); + + free(result); } void replace_when_new_empty(void **state) @@ -135,6 +155,8 @@ void replace_when_new_empty(void **state) char *result = str_replace(string, sub, new); assert_string_equal("", result); + + free(result); } void replace_when_new_null(void **state) @@ -146,6 +168,8 @@ void replace_when_new_null(void **state) char *result = str_replace(string, sub, new); assert_string_equal("hello", result); + + free(result); } void compare_win_nums_less(void **state)