fix more memleaks
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
diff --git a/lib/inflate.c b/lib/inflate.c
index c8bef69..89c49ef 100644
--- a/lib/inflate.c
+++ b/lib/inflate.c
@@ -310,7 +310,7 @@ got_inflate_to_mem_mmap(uint8_t **outbuf, size_t *outlen, uint8_t *map,
err = got_inflate_read_mmap(&zb, map, offset, len, &avail,
&consumed);
if (err)
- return err;
+ goto done;
offset += consumed;
len -= consumed;
*outlen += avail;
diff --git a/lib/pack.c b/lib/pack.c
index 1c66bfa..eaca831 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -983,7 +983,7 @@ resolve_ref_delta(struct got_delta_chain *deltas, struct got_repository *repo,
uint64_t base_size;
size_t base_tslen;
off_t delta_data_offset;
- uint8_t *delta_buf;
+ uint8_t *delta_buf = NULL;
size_t delta_len;
if (delta_offset >= pack->filesize)
@@ -1006,7 +1006,7 @@ resolve_ref_delta(struct got_delta_chain *deltas, struct got_repository *repo,
err = got_inflate_to_mem_mmap(&delta_buf, &delta_len, pack->map,
mapoff, pack->filesize - mapoff);
if (err)
- return err;
+ goto done;
} else {
ssize_t n = read(pack->fd, &id, sizeof(id));
if (n < 0)
@@ -1015,22 +1015,25 @@ resolve_ref_delta(struct got_delta_chain *deltas, struct got_repository *repo,
return got_error(GOT_ERR_BAD_PACKFILE);
err = got_inflate_to_mem_fd(&delta_buf, &delta_len, pack->fd);
if (err)
- return err;
+ goto done;
}
err = add_delta(deltas, pack->path_packfile, delta_offset, tslen,
delta_type, delta_size, delta_data_offset, delta_buf, delta_len);
if (err)
- return err;
+ goto done;
/* Delta base must be in the same pack file. */
idx = get_object_idx(packidx, &id, repo);
- if (idx == -1)
- return got_error(GOT_ERR_BAD_PACKFILE);
+ if (idx == -1) {
+ err = got_error(GOT_ERR_BAD_PACKFILE);
+ goto done;
+ }
base_offset = get_object_offset(packidx, idx);
if (base_offset == (uint64_t)-1) {
- return got_error(GOT_ERR_BAD_PACKIDX);
+ err = got_error(GOT_ERR_BAD_PACKIDX);
+ goto done;
}
if (base_offset >= pack->filesize) {
@@ -1046,6 +1049,8 @@ resolve_ref_delta(struct got_delta_chain *deltas, struct got_repository *repo,
err = resolve_delta_chain(deltas, repo, packidx, pack, base_offset,
base_tslen, base_type, base_size, recursion - 1);
done:
+ if (err)
+ free(delta_buf);
return err;
}