From 94271805633a1ee5487b036dfd81b63c0250df39 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 8 Aug 2012 17:11:52 +0200 Subject: geo-rep: don't leak or segfault upon OOM In glusterd_urltransform, a failed GF_REALLOC would clobber the would-be-realloc'd buffer, linearr, with a NULL pointer, (thus leaking that memory) and then control would pass to the error-handling code that would attempt to free (via glusterd_urltransform_free) linearr[i], which is almost guaranteed to segfault when linearr is NULL. Change-Id: Ia75bf70fd8ff893a18804d49688048ef96db6037 BUG: 846755 Signed-off-by: Jim Meyering Reviewed-on: http://review.gluster.com/3791 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- xlators/mgmt/glusterd/src/glusterd-geo-rep.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'xlators/mgmt/glusterd/src/glusterd-geo-rep.c') diff --git a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c index 901e5e1e..db0ab9cc 100644 --- a/xlators/mgmt/glusterd/src/glusterd-geo-rep.c +++ b/xlators/mgmt/glusterd/src/glusterd-geo-rep.c @@ -249,13 +249,15 @@ glusterd_urltransform (runner_t *runner, char ***linearrp) line[len - 1] = '\0'; if (arr_idx == arr_len) { + void *p = linearr; arr_len <<= 1; - linearr = GF_REALLOC (linearr, arr_len); - if (!linearr) { + p = GF_REALLOC (linearr, arr_len); + if (!p) { GF_FREE (line); error = _gf_true; goto out; } + linearr = p; } linearr[arr_idx] = line; -- cgit