Commit Diff


commit - 345f650943608219909e5b5b0e5d77c4c9ca26bb
commit + b1fad72fdca8c2a237161cac88778e31a58bccb1
blob - 2d666ed27a880d2f0d3809c5a2e9f56c721952a3
blob + cc7e1998317d976ae382059d27ef242fea2d6cb0
--- lib/pack.c
+++ lib/pack.c
@@ -1492,8 +1492,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)
@@ -1505,6 +1508,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);
@@ -1517,6 +1522,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;
@@ -1527,6 +1534,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;
@@ -1680,8 +1689,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)
@@ -1691,6 +1703,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;
@@ -1701,6 +1715,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;