* [PATCH] bundle: plug minor memory leak in is_tag_in_date_range()
@ 2014-10-03 22:40 René Scharfe
2014-10-03 23:40 ` Jonathan Nieder
0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2014-10-03 22:40 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano
Free the buffer returned by read_sha1_file() even if no valid tagger
line is found.
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
bundle.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/bundle.c b/bundle.c
index b2b89fe..9ed865c 100644
--- a/bundle.c
+++ b/bundle.c
@@ -211,24 +211,28 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
enum object_type type;
char *buf, *line, *lineend;
unsigned long date;
+ int result = 1;
if (revs->max_age == -1 && revs->min_age == -1)
- return 1;
+ goto out;
buf = read_sha1_file(tag->sha1, &type, &size);
if (!buf)
- return 1;
+ goto out;
line = memmem(buf, size, "\ntagger ", 8);
if (!line++)
- return 1;
+ goto out_free;
lineend = memchr(line, '\n', buf + size - line);
line = memchr(line, '>', lineend ? lineend - line : buf + size - line);
if (!line++)
- return 1;
+ goto out_free;
date = strtoul(line, NULL, 10);
- free(buf);
- return (revs->max_age == -1 || revs->max_age < date) &&
+ result = (revs->max_age == -1 || revs->max_age < date) &&
(revs->min_age == -1 || revs->min_age > date);
+out_free:
+ free(buf);
+out:
+ return result;
}
int create_bundle(struct bundle_header *header, const char *path,
--
2.1.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] bundle: plug minor memory leak in is_tag_in_date_range()
2014-10-03 22:40 [PATCH] bundle: plug minor memory leak in is_tag_in_date_range() René Scharfe
@ 2014-10-03 23:40 ` Jonathan Nieder
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Nieder @ 2014-10-03 23:40 UTC (permalink / raw)
To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano
René Scharfe wrote:
> --- a/bundle.c
> +++ b/bundle.c
> @@ -211,24 +211,28 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
> enum object_type type;
> char *buf, *line, *lineend;
If buf is initialized to NULL, there is no need for separate out and
out_free labels.
With or without such a change,
Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>
diff --git i/bundle.c w/bundle.c
index 4158e11..101cde0 100644
--- i/bundle.c
+++ w/bundle.c
@@ -209,7 +209,7 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
{
unsigned long size;
enum object_type type;
- char *buf, *line, *lineend;
+ char *buf = NULL, *line, *lineend;
unsigned long date;
int result = 1;
@@ -221,17 +221,16 @@ static int is_tag_in_date_range(struct object *tag, struct rev_info *revs)
goto out;
line = memmem(buf, size, "\ntagger ", 8);
if (!line++)
- goto out_free;
+ goto out;
lineend = memchr(line, '\n', buf + size - line);
line = memchr(line, '>', lineend ? lineend - line : buf + size - line);
if (!line++)
- goto out_free;
+ goto out;
date = strtoul(line, NULL, 10);
result = (revs->max_age == -1 || revs->max_age < date) &&
(revs->min_age == -1 || revs->min_age > date);
-out_free:
- free(buf);
out:
+ free(buf);
return result;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-10-03 23:40 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-03 22:40 [PATCH] bundle: plug minor memory leak in is_tag_in_date_range() René Scharfe
2014-10-03 23:40 ` Jonathan Nieder
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).