fix bogus free() in got_object_open_by_path()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/lib/object.c b/lib/object.c
index f5552d9..d5e33de 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -1406,7 +1406,7 @@ got_object_open_by_path(struct got_object **obj, struct got_repository *repo,
struct got_commit_object *commit = NULL;
struct got_tree_object *tree = NULL;
struct got_tree_entry *entry = NULL;
- char *seg, *s = NULL;
+ char *seg, *s, *s0 = NULL;
*obj = NULL;
@@ -1430,15 +1430,16 @@ got_object_open_by_path(struct got_object **obj, struct got_repository *repo,
if (err)
goto done;
- s = strdup(path);
- if (s == NULL) {
+ s0 = strdup(path);
+ if (s0 == NULL) {
err = got_error_from_errno();
goto done;
}
- err = got_canonpath(path, s, strlen(s) + 1);
+ err = got_canonpath(path, s0, strlen(s0) + 1);
if (err)
goto done;
+ s = s0;
s++; /* skip leading '/' */
seg = s;
while (*s) {
@@ -1477,7 +1478,7 @@ got_object_open_by_path(struct got_object **obj, struct got_repository *repo,
else
err = got_error(GOT_ERR_NO_OBJ);
done:
- free(s);
+ free(s0);
if (commit)
got_object_commit_close(commit);
if (tree)