don't leak memory for pack file path when opening objects
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
diff --git a/lib/object.c b/lib/object.c
index 90e8331..63fbc85 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -581,7 +581,7 @@ open_commit(struct got_commit_object **commit,
const struct got_error *err = NULL;
struct got_packidx *packidx = NULL;
int idx;
- char *path_packfile;
+ char *path_packfile = NULL;
if (check_cache) {
*commit = got_repo_get_cached_commit(repo, id);
@@ -605,7 +605,7 @@ open_commit(struct got_commit_object **commit,
err = got_repo_cache_pack(&pack, repo, path_packfile,
packidx);
if (err)
- return err;
+ goto done;
}
err = read_packed_commit_privsep(commit, pack,
packidx, idx, id);
@@ -622,7 +622,8 @@ open_commit(struct got_commit_object **commit,
(*commit)->refcnt++;
err = got_repo_cache_commit(repo, id, *commit);
}
-
+done:
+ free(path_packfile);
return err;
}
@@ -759,7 +760,7 @@ open_tree(struct got_tree_object **tree, struct got_repository *repo,
const struct got_error *err = NULL;
struct got_packidx *packidx = NULL;
int idx;
- char *path_packfile;
+ char *path_packfile = NULL;
if (check_cache) {
*tree = got_repo_get_cached_tree(repo, id);
@@ -783,7 +784,7 @@ open_tree(struct got_tree_object **tree, struct got_repository *repo,
err = got_repo_cache_pack(&pack, repo, path_packfile,
packidx);
if (err)
- return err;
+ goto done;
}
err = read_packed_tree_privsep(tree, pack,
packidx, idx, id);
@@ -800,7 +801,8 @@ open_tree(struct got_tree_object **tree, struct got_repository *repo,
(*tree)->refcnt++;
err = got_repo_cache_tree(repo, id, *tree);
}
-
+done:
+ free(path_packfile);
return err;
}
@@ -978,7 +980,7 @@ open_blob(struct got_blob_object **blob, struct got_repository *repo,
const struct got_error *err = NULL;
struct got_packidx *packidx = NULL;
int idx;
- char *path_packfile;
+ char *path_packfile = NULL;
uint8_t *outbuf;
int outfd;
size_t size, hdrlen;
@@ -1068,6 +1070,7 @@ open_blob(struct got_blob_object **blob, struct got_repository *repo,
memcpy(&(*blob)->id.sha1, id->sha1, SHA1_DIGEST_LENGTH);
done:
+ free(path_packfile);
if (err) {
if (*blob) {
got_object_blob_close(*blob);
@@ -1303,7 +1306,7 @@ open_tag(struct got_tag_object **tag, struct got_repository *repo,
const struct got_error *err = NULL;
struct got_packidx *packidx = NULL;
int idx;
- char *path_packfile;
+ char *path_packfile = NULL;
if (check_cache) {
*tag = got_repo_get_cached_tag(repo, id);
@@ -1327,7 +1330,7 @@ open_tag(struct got_tag_object **tag, struct got_repository *repo,
err = got_repo_cache_pack(&pack, repo, path_packfile,
packidx);
if (err)
- return err;
+ goto done;
}
err = read_packed_tag_privsep(tag, pack,
packidx, idx, id);
@@ -1344,7 +1347,8 @@ open_tag(struct got_tag_object **tag, struct got_repository *repo,
(*tag)->refcnt++;
err = got_repo_cache_tag(repo, id, *tag);
}
-
+done:
+ free(path_packfile);
return err;
}