Skip to content

Commit 6404594

Browse files
rscharfegitster
authored andcommitted
bundle: plug minor memory leak in is_tag_in_date_range()
Free the buffer returned by read_sha1_file() even if no valid tagger line is found. Signed-off-by: Rene Scharfe <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80b616d commit 6404594

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

bundle.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,26 +209,29 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
209209
{
210210
unsigned long size;
211211
enum object_type type;
212-
char *buf, *line, *lineend;
212+
char *buf = NULL, *line, *lineend;
213213
unsigned long date;
214+
int result = 1;
214215

215216
if (revs->max_age == -1 && revs->min_age == -1)
216-
return 1;
217+
goto out;
217218

218219
buf = read_sha1_file(tag->sha1, &type, &size);
219220
if (!buf)
220-
return 1;
221+
goto out;
221222
line = memmem(buf, size, "\ntagger ", 8);
222223
if (!line++)
223-
return 1;
224+
goto out;
224225
lineend = memchr(line, '\n', buf + size - line);
225226
line = memchr(line, '>', lineend ? lineend - line : buf + size - line);
226227
if (!line++)
227-
return 1;
228+
goto out;
228229
date = strtoul(line, NULL, 10);
229-
free(buf);
230-
return (revs->max_age == -1 || revs->max_age < date) &&
230+
result = (revs->max_age == -1 || revs->max_age < date) &&
231231
(revs->min_age == -1 || revs->min_age > date);
232+
out:
233+
free(buf);
234+
return result;
232235
}
233236

234237
int create_bundle(struct bundle_header *header, const char *path,

0 commit comments

Comments
 (0)