Browse Source

tal/path: fix unset vars in error paths.

Compiling with optimization FTW.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rusty Russell 12 years ago
parent
commit
ba57295a55
1 changed files with 6 additions and 2 deletions
  1. 6 2
      ccan/tal/path/path.c

+ 6 - 2
ccan/tal/path/path.c

@@ -244,8 +244,10 @@ char *path_rel(const tal_t *ctx, const char *from, const char *to)
 
 	/* This frees to if we're supposed to take it. */
 	cto = path_canon(tmpctx, to);
-	if (!cto)
+	if (!cto) {
+		ret = NULL;
 		goto out;
+	}
 
 	/* How much is in common? */
 	for (common = i = 0; cfrom[i] && cto[i]; i++) {
@@ -323,7 +325,9 @@ fail_take_to:
 			goto fail;
 	}
 
-	ret[len] = '\0';
+	if (ret)
+		ret[len] = '\0';
+
 out:
 	if (taken(linkname))
 		tal_free(linkname);