From: Rusty Russell Date: Mon, 12 Sep 2011 03:54:34 +0000 (+0930) Subject: tools: fix realloc bug. X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=73753f596f5a588b90bc7ec19773173ec36230be tools: fix realloc bug. Reallocing smaller can move the pointer; certainly valgrind detects it. Found while chasing intermittant errors on "make fastcheck". --- diff --git a/tools/depends.c b/tools/depends.c index 041af49e..f1e45c50 100644 --- a/tools/depends.c +++ b/tools/depends.c @@ -235,7 +235,7 @@ char **get_libs(const void *ctx, const char *dir, } /* FIXME: This is O(n^2), which is dumb. */ -static void uniquify_deps(char **deps) +static char **uniquify_deps(char **deps) { unsigned int i, j, num; @@ -251,7 +251,7 @@ static void uniquify_deps(char **deps) } deps[num] = NULL; /* Make sure talloc_array_length() works */ - deps = talloc_realloc(NULL, deps, char *, num + 1); + return talloc_realloc(NULL, deps, char *, num + 1); } char **get_deps(const void *ctx, const char *dir, @@ -270,8 +270,7 @@ char **get_deps(const void *ctx, const char *dir, unlink(temp); talloc_free(temp); } - uniquify_deps(ret); - return ret; + return uniquify_deps(ret); } char **get_safe_ccan_deps(const void *ctx, const char *dir, @@ -283,6 +282,5 @@ char **get_safe_ccan_deps(const void *ctx, const char *dir, } else { ret = get_all_deps(ctx, dir, NULL, get_one_safe_deps); } - uniquify_deps(ret); - return ret; + return uniquify_deps(ret); }