From 9ce8fc70683d4d7632b7ff5868766e361ac3d8e8 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Sat, 22 Feb 2014 12:28:19 +0100 Subject: [PATCH] core: fix memory leak and use of invalid pointer in split of string (in case of insufficient memory) --- ChangeLog | 2 ++ src/core/wee-string.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/ChangeLog b/ChangeLog index 10b859aed..0da74bb3f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,8 @@ http://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes] == Version 0.4.4 (under dev) +* core: fix memory leak and use of invalid pointer in split of string (in case + of insufficient memory) * core: fix potential NULL pointer in function gui_color_emphasize * core: use same return code and message in all commands when arguments are wrong/missing diff --git a/src/core/wee-string.c b/src/core/wee-string.c index 08fb4c7e1..04bd4cb1a 100644 --- a/src/core/wee-string.c +++ b/src/core/wee-string.c @@ -1467,7 +1467,14 @@ string_split_internal (const char *string, const char *separators, int keep_eol, array = malloc ((n_items + 1) * sizeof (array[0])); if (!array) + { + free (string2); return NULL; + } + for (i = 0; i < n_items + 1; i++) + { + array[i] = NULL; + } ptr1 = string2;