From 53d7f6cf18188ce82c0c24c468bd22cfe517b675 Mon Sep 17 00:00:00 2001 From: WaLyong Cho Date: Tue, 8 Nov 2016 19:27:01 +0900 Subject: [PATCH] libsystem: strv: avoid memory leak by realloc In str_to_strv(), during interation the strings if allocation is failed after second chance, the allocated origin value v is leaked. And recent gcc is safe for null free. So destroy value without check. Change-Id: I7fda4d76484201b2ccb66f5617ca75d0e4ecb1aa Signed-off-by: WaLyong Cho --- src/libsystem/libsystem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libsystem/libsystem.c b/src/libsystem/libsystem.c index 0159c03..f7aa2e3 100644 --- a/src/libsystem/libsystem.c +++ b/src/libsystem/libsystem.c @@ -731,14 +731,14 @@ int str_to_strv(const char *str, char ***strv, const char *separator) { FOREACH_WORD_SEPARATOR(w, l, str, separator, state) { p = strndup(w, l); if (!p) { - if (v) - free(v); + free(v); return -ENOMEM; } new = (char **)realloc(v, sizeof(char *) * (i + 2)); if (!new) { free(p); + free(v); p = NULL; return -ENOMEM; } -- 2.34.1