commit 8d2c5ea3cf75adc256f3fc1b9cd19667fe6f8d07 from: Stefan Sperling date: Tue Aug 13 08:50:17 2019 UTC don't leak memory for pack file path when opening objects commit - a436ad14b580220cf835e8386b241b42903a0339 commit + 8d2c5ea3cf75adc256f3fc1b9cd19667fe6f8d07 blob - 90e8331aa0d5ab5db7909bb85d3c2623d80126eb blob + 63fbc857f6aca730ac30a8872e56c453ca7b60a3 --- lib/object.c +++ 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_re 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_re 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_re (*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_re 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_re 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_repos 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_repos 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_repos (*tag)->refcnt++; err = got_repo_cache_tag(repo, id, *tag); } - +done: + free(path_packfile); return err; }