summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWaLyong Cho <walyong.cho@samsung.com>2016-11-08 10:27:01 (GMT)
committerWaLyong Cho <walyong.cho@samsung.com>2016-11-08 10:29:57 (GMT)
commit53d7f6cf18188ce82c0c24c468bd22cfe517b675 (patch)
tree160043233a3fa5d51cf70571f93f266495453127
parent4809efe44e7ecee13a1c2b19fb3114621f1e3c12 (diff)
downloadlibsystem-53d7f6cf18188ce82c0c24c468bd22cfe517b675.zip
libsystem-53d7f6cf18188ce82c0c24c468bd22cfe517b675.tar.gz
libsystem-53d7f6cf18188ce82c0c24c468bd22cfe517b675.tar.bz2
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 <walyong.cho@samsung.com>
-rw-r--r--src/libsystem/libsystem.c4
1 files 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;
}