Hi , please ignore previous mail. Please find below correct patch. >From 1a0269a1c24ac8ee07ac5d0133f2f816468e50d1 Mon Sep 17 00:00:00 2001 From: Manjeet Pawar <manjee...@samsung.com> Date: Tue, 2 Jun 2015 08:57:19 +0530 Subject: [PATCH] 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.g...@samsung.com> Signed-off-by: Manjeet Pawar <manjee...@samsung.com> --- pan/splitstr.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pan/splitstr.c b/pan/splitstr.c index 4706323..4636399 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,12 @@ 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_array); + free(arg_string); + exit(1); + } } } arg_array[num_toks] = NULL; -- 1.7.9.5 Regards Manjeet ------- Original Message ------- Sender : Cyril Hrubis<chru...@suse.cz> Date : Jun 01, 2015 23:22 (GMT+09:00) Title : Re: [LTP] [PATCH]: Add check for realloc failure case Hi! > @@ -110,9 +111,13 @@ const char **splitstr(const char *str, const char > *separator, int *argcount) > cur_tok = strtok(NULL, separator); > if (num_toks == max_toks) { > max_toks += 20; > - arg_array = > - (char **)realloc((void *)arg_array, > - sizeof(char *) * max_toks); > + if((arg_array = realloc((void *)arg_array,sizeof(char *) * max_toks)) == > NULL){ > + fprintf(stderr, "realloc: New memory allocation failed \n"); > + free(arg_array); > + free(arg_string); > + exit(1); > + } > + These lines does not conform to LKML coding style. There should be space before the opening curly brace '{', spaces after coma, etc. You can use checkpatch.pl shipped with linux kernel source to check your patches before sending them. -- Cyril Hrubis chru...@suse.cz ------------------------------------------------------------------------------ _______________________________________________ Ltp-list mailing list Ltp-list@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ltp-list