Commit 73753f59 authored by Rusty Russell's avatar Rusty Russell

tools: fix realloc bug.

Reallocing smaller can move the pointer; certainly valgrind detects
it.  Found while chasing intermittant errors on "make fastcheck".
parent ce859a2e
...@@ -235,7 +235,7 @@ char **get_libs(const void *ctx, const char *dir, ...@@ -235,7 +235,7 @@ char **get_libs(const void *ctx, const char *dir,
} }
/* FIXME: This is O(n^2), which is dumb. */ /* 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; unsigned int i, j, num;
...@@ -251,7 +251,7 @@ static void uniquify_deps(char **deps) ...@@ -251,7 +251,7 @@ static void uniquify_deps(char **deps)
} }
deps[num] = NULL; deps[num] = NULL;
/* Make sure talloc_array_length() works */ /* 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, char **get_deps(const void *ctx, const char *dir,
...@@ -270,8 +270,7 @@ char **get_deps(const void *ctx, const char *dir, ...@@ -270,8 +270,7 @@ char **get_deps(const void *ctx, const char *dir,
unlink(temp); unlink(temp);
talloc_free(temp); talloc_free(temp);
} }
uniquify_deps(ret); return uniquify_deps(ret);
return ret;
} }
char **get_safe_ccan_deps(const void *ctx, const char *dir, 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, ...@@ -283,6 +282,5 @@ char **get_safe_ccan_deps(const void *ctx, const char *dir,
} else { } else {
ret = get_all_deps(ctx, dir, NULL, get_one_safe_deps); ret = get_all_deps(ctx, dir, NULL, get_one_safe_deps);
} }
uniquify_deps(ret); return uniquify_deps(ret);
return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment