Commit Diff


commit - 99f7567eaa6fad9b271f55d1469fcd383bb13205
commit + e62fc5205c7c439d072229d8be922ea30e8d8024
blob - b9fe3f13bee15721a2972403a9e9e692dafb6531
blob + 890220f4bbc04471e5b17866775b2696968d025b
--- lib/pack.c
+++ lib/pack.c
@@ -1495,8 +1495,11 @@ got_pack_dump_delta_chain_to_file(size_t *result_size,
 
 		err = got_delta_get_sizes(&base_size, &result_size,
 		    delta_buf, delta_len);
-		if (err)
+		if (err) {
+			if (!cached)
+				free(delta_buf);
 			goto done;
+		}
 		if (base_size > max_size)
 			max_size = base_size;
 		if (result_size > max_size)
@@ -1508,6 +1511,8 @@ got_pack_dump_delta_chain_to_file(size_t *result_size,
 			    base_file);
 			if (w != base_bufsz) {
 				err = got_ferror(outfile, GOT_ERR_IO);
+				if (!cached)
+					free(delta_buf);
 				goto done;
 			}
 			free(base_buf);
@@ -1520,6 +1525,8 @@ got_pack_dump_delta_chain_to_file(size_t *result_size,
 			uint8_t *p = realloc(base_buf, max_size);
 			if (p == NULL) {
 				err = got_error_from_errno("realloc");
+				if (!cached)
+					free(delta_buf);
 				goto done;
 			}
 			base_buf = p;
@@ -1530,6 +1537,8 @@ got_pack_dump_delta_chain_to_file(size_t *result_size,
 			uint8_t *p = realloc(accum_buf, max_size);
 			if (p == NULL) {
 				err = got_error_from_errno("realloc");
+				if (!cached)
+					free(delta_buf);
 				goto done;
 			}
 			accum_buf = p;
@@ -1683,8 +1692,11 @@ got_pack_dump_delta_chain_to_mem(uint8_t **outbuf, siz
 
 		err = got_delta_get_sizes(&base_size, &result_size,
 		    delta_buf, delta_len);
-		if (err)
+		if (err) {
+			if (!cached)
+				free(delta_buf);
 			goto done;
+		}
 		if (base_size > max_size)
 			max_size = base_size;
 		if (result_size > max_size)
@@ -1694,6 +1706,8 @@ got_pack_dump_delta_chain_to_mem(uint8_t **outbuf, siz
 			uint8_t *p = realloc(base_buf, max_size);
 			if (p == NULL) {
 				err = got_error_from_errno("realloc");
+				if (!cached)
+					free(delta_buf);
 				goto done;
 			}
 			base_buf = p;
@@ -1704,6 +1718,8 @@ got_pack_dump_delta_chain_to_mem(uint8_t **outbuf, siz
 			uint8_t *p = realloc(accum_buf, max_size);
 			if (p == NULL) {
 				err = got_error_from_errno("realloc");
+				if (!cached)
+					free(delta_buf);
 				goto done;
 			}
 			accum_buf = p;