From 2ca64411fd134eb03fc8b40dec91e94027ad82b1 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Tue, 19 May 2015 17:24:45 +0530 Subject: geo-replication: fix memory leak in gsyncd 1. leak in str2argv() function: char *strdup(const char *s); The strdup() function returns a pointer to a new string which is a duplicate of the string s. Memory for the new string is obtained with malloc(3), and can be freed with free(3). so when using strdup, user has to take care of freeing the memory allocated by strdup library function. 2. leak in main() function: str2argv() function calls calloc and allocates memory pointed to argv, after return from str2argv() memory pointed to argv has to be cleaned in main(). This patch is to fix 2 memory leaks mentioned above. Change-Id: I6bf26101e0460a7324ac7bdb69905839688d4987 BUG: 1222898 Signed-off-by: Prasanna Kumar Kalever Reviewed-on: http://review.gluster.org/10831 Tested-by: NetBSD Build System Reviewed-by: Milind Changire Reviewed-by: Kotresh HR Reviewed-by: Venky Shankar --- geo-replication/src/gsyncd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/geo-replication/src/gsyncd.c b/geo-replication/src/gsyncd.c index 7f1365a49da..018b4429176 100644 --- a/geo-replication/src/gsyncd.c +++ b/geo-replication/src/gsyncd.c @@ -61,12 +61,13 @@ str2argv (char *str, char ***argv) { char *p = NULL; char *savetok = NULL; + char *temp = NULL; int argc = 0; size_t argv_len = 32; int ret = 0; assert (str); - str = strdup (str); + temp = str = strdup (str); if (!str) return -1; @@ -88,10 +89,12 @@ str2argv (char *str, char ***argv) (*argv)[argc - 1] = p; } + free(temp); return argc; error: fprintf (stderr, "out of memory\n"); + free(temp); return -1; } @@ -407,5 +410,6 @@ main (int argc, char **argv) fprintf (stderr, "invoking %s in restricted SSH session is not allowed\n", b); + free(argv); return 1; } -- cgit