Skip to content

Commit 9ce4ad3

Browse files
johnkeepinggitster
authored andcommitted
streaming.c: fix a memleak
When stream_blob_to_fd() opens an input stream with a filter, the filter gets discarded upon calling close_istream() before the function returns in the normal case. However, when we fail to open the stream, we failed to discard the filter. By discarding the filter in the failure case, give a consistent life-time rule of the filter to the callers; otherwise the callers need to conditionally discard the filter themselves, and this function does not give enough hint for the caller to do so correctly. Signed-off-by: John Keeping <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 47a02ff commit 9ce4ad3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

streaming.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,8 +505,11 @@ int stream_blob_to_fd(int fd, unsigned const char *sha1, struct stream_filter *f
505505
int result = -1;
506506

507507
st = open_istream(sha1, &type, &sz, filter);
508-
if (!st)
508+
if (!st) {
509+
if (filter)
510+
free_stream_filter(filter);
509511
return result;
512+
}
510513
if (type != OBJ_BLOB)
511514
goto close_and_exit;
512515
for (;;) {

0 commit comments

Comments
 (0)