commit cb5e38fd43cb415cf405819e2cd437067cbf4397 from: Stefan Sperling date: Thu May 23 19:52:49 2019 UTC fix some leaks in got-read-pack commit - 704b89c4330d9641c93302516a59957a847736c1 commit + cb5e38fd43cb415cf405819e2cd437067cbf4397 blob - 7147a9755c2e0788c9ee549a1d956e32fe1c80b9 blob + a59aa24e783ca60c92019b12f4a166d4a4fe70ab --- libexec/got-read-pack/got-read-pack.c +++ libexec/got-read-pack/got-read-pack.c @@ -109,9 +109,9 @@ commit_request(struct imsg *imsg, struct imsgbuf *ibuf { const struct got_error *err = NULL; struct got_imsg_packed_object iobj; - struct got_object *obj; + struct got_object *obj = NULL; struct got_commit_object *commit = NULL; - uint8_t *buf; + uint8_t *buf = NULL; size_t len; struct got_object_id id; size_t datalen; @@ -134,18 +134,19 @@ commit_request(struct imsg *imsg, struct imsgbuf *ibuf err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack); if (err) - return err; + goto done; obj->size = len; err = got_object_parse_commit(&commit, buf, len); - free(buf); - if (err) { - got_object_close(obj); - return err; - } + if (err) + goto done; err = got_privsep_send_commit(ibuf, commit); - got_object_commit_close(commit); +done: + free(buf); + got_object_close(obj); + if (commit) + got_object_commit_close(commit); if (err) { if (err->code == GOT_ERR_PRIVSEP_PIPE) err = NULL; @@ -164,7 +165,7 @@ tree_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_imsg_packed_object iobj; struct got_object *obj = NULL; struct got_tree_object *tree = NULL; - uint8_t *buf; + uint8_t *buf = NULL; size_t len; struct got_object_id id; size_t datalen; @@ -187,16 +188,19 @@ tree_request(struct imsg *imsg, struct imsgbuf *ibuf, err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack); if (err) - return err; + goto done; obj->size = len; err = got_object_parse_tree(&tree, buf, len); - free(buf); + if (err) + goto done; err = got_privsep_send_tree(ibuf, tree); - if (obj) - got_object_close(obj); - got_object_tree_close(tree); +done: + free(buf); + got_object_close(obj); + if (tree) + got_object_tree_close(tree); if (err) { if (err->code == GOT_ERR_PRIVSEP_PIPE) err = NULL; @@ -308,8 +312,7 @@ done: err = got_error_from_errno("fclose"); if (accumfile && fclose(accumfile) != 0 && err == NULL) err = got_error_from_errno("fclose"); - if (obj) - got_object_close(obj); + got_object_close(obj); if (err && err->code != GOT_ERR_PRIVSEP_PIPE) got_privsep_send_error(ibuf, err); @@ -324,7 +327,7 @@ tag_request(struct imsg *imsg, struct imsgbuf *ibuf, s struct got_imsg_packed_object iobj; struct got_object *obj = NULL; struct got_tag_object *tag = NULL; - uint8_t *buf; + uint8_t *buf = NULL; size_t len; struct got_object_id id; size_t datalen; @@ -347,18 +350,19 @@ tag_request(struct imsg *imsg, struct imsgbuf *ibuf, s err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack); if (err) - return err; + goto done; obj->size = len; err = got_object_parse_tag(&tag, buf, len); - free(buf); if (err) - return err; + goto done; err = got_privsep_send_tag(ibuf, tag); - if (obj) - got_object_close(obj); - got_object_tag_close(tag); +done: + free(buf); + got_object_close(obj); + if (tag) + got_object_tag_close(tag); if (err) { if (err->code == GOT_ERR_PRIVSEP_PIPE) err = NULL;