aboutsummaryrefslogtreecommitdiff
path: root/pan
diff options
context:
space:
mode:
authorManjeet Pawar <manjeet.p@samsung.com>2015-06-02 08:57:19 +0530
committerCyril Hrubis <chrubis@suse.cz>2015-06-04 18:22:22 +0200
commit4989990ba2736ad18150853d78d846048cb44aaa (patch)
tree11087f7ef656e1fb74f7000a0a3fbd57a5bbb9a5 /pan
parent95cc8bb6f4bf9077ea5bcfc3998458cd6dac9ee2 (diff)
pan/splitstr.c: Add check for realloc failure case
This patch adds check for realloc failure case and free arg_string before returning from splitstr() to avoid memory leaks Signed-off-by: Yogesh Gaur <yn.gaur@samsung.com> Signed-off-by: Manjeet Pawar <manjeet.p@samsung.com> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
Diffstat (limited to 'pan')
-rw-r--r--pan/splitstr.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/pan/splitstr.c b/pan/splitstr.c
index 4706323a8..fbcd69700 100644
--- a/pan/splitstr.c
+++ b/pan/splitstr.c
@@ -93,6 +93,7 @@ const char **splitstr(const char *str, const char *separator, int *argcount)
if (arg_array == NULL) {
if (argcount != NULL)
*argcount = 0;
+ free(arg_string);
return (NULL);
}
@@ -113,6 +114,11 @@ const char **splitstr(const char *str, const char *separator, int *argcount)
arg_array =
(char **)realloc((void *)arg_array,
sizeof(char *) * max_toks);
+ if (arg_array == NULL) {
+ fprintf(stderr, "realloc: New memory allocation failed \n");
+ free(arg_string);
+ exit(1);
+ }
}
}
arg_array[num_toks] = NULL;