commit 19d60ee3e107682f62ef5f79ccc2e10a28b6d533 from: Omar Polo via: Thomas Adam date: Fri Sep 02 15:54:01 2022 UTC gotwebd: plug some leaks in got_get_repo_tags ok stsp@ commit - f95e65a1d73cdc27fb408e34c6934bbdc8c3abe1 commit + 19d60ee3e107682f62ef5f79ccc2e10a28b6d533 blob - a488ecb36b8d42ef742cd59f436be51df144be4d blob + 4fd7e0997a19d68b850d6815af413765d91aa206 --- gotwebd/got_operations.c +++ gotwebd/got_operations.c @@ -644,24 +644,24 @@ got_get_repo_tags(struct request *c, int limit) goto err; } + free(id); + id = NULL; + + free(id_str); + id_str = NULL; + error = got_ref_resolve(&id, repo, re->ref); if (error) goto done; error = got_object_open_as_tag(&tag, repo, id); if (error) { - if (error->code != GOT_ERR_OBJ_TYPE) { - free(id); - id = NULL; + if (error->code != GOT_ERR_OBJ_TYPE) goto done; - } /* "lightweight" tag */ error = got_object_open_as_commit(&commit, repo, id); - if (error) { - free(id); - id = NULL; + if (error) goto done; - } new_repo_tag->tagger = strdup(got_object_commit_get_committer(commit)); if (new_repo_tag->tagger == NULL) { @@ -673,11 +673,7 @@ got_get_repo_tags(struct request *c, int limit) error = got_object_id_str(&id_str, id); if (error) goto err; - free(id); - id = NULL; } else { - free(id); - id = NULL; new_repo_tag->tagger = strdup(got_object_tag_get_tagger(tag)); if (new_repo_tag->tagger == NULL) { @@ -690,6 +686,9 @@ got_get_repo_tags(struct request *c, int limit) got_object_tag_get_object_id(tag)); if (error) goto err; + + got_object_tag_close(tag); + tag = NULL; } new_repo_tag->commit_id = strdup(id_str); @@ -769,8 +768,6 @@ got_get_repo_tags(struct request *c, int limit) break; chk_next = 1; } - free(id); - id = NULL; } done: @@ -806,9 +803,13 @@ done: err: if (commit) got_object_commit_close(commit); + if (tag) + got_object_tag_close(tag); got_ref_list_free(&refs); + free(in_repo_path); free(repo_path); free(id); + free(id_str); return error; }