remote.c: free previous results when looking for a ref match
PATCH 1/1 remote.c: free previous results when looking for a ref match
--- remote.c | 4 ++++ 1 file changed, 4 insertions(+)
remote.c +4 -0
@@ -833,6 +833,8 @@ static int match_name_with_pattern(const char *key, const char *name,strbuf_add (&sb, value, vstar - value);strbuf_add (&sb, name + klen, namelen - klen - ksuffixlen);strbuf_addstr (&sb, vstar +1 ); +if (*result) +free (*result); *result =strbuf_detach (&sb,NULL ); }return ret;
@@ -1262,6 +1264,8 @@ static char *get_ref_match(const struct refspec *rs, int rs_nr, const struct ref*/ if (!send_mirror && !starts_with (ref->name,"refs/heads/" ))return NULL ; +if (name) +free (name); name =xstrdup (ref->name); }if (ret_pat)
Signature · 1 line
2.10.1.353.g1629400
Am 08.10.2016 um 01:58 schrieb Stefan Beller:
Quoted 10 lines
Signed-off-by Stefan Beller <[email protected]>--- remote.c | 4 ++++ 1 file changed, 4 insertions(+)remote.c +0
-0
remote.c static int match_name_with_pattern(const char *key, const char *name, · line 837
Quoted 5 lines
remote.c +2
-0@@ -833,6 +833,8 @@ static int match_name_with_pattern(const char *key, const char *name,strbuf_add (&sb, value, vstar - value);strbuf_add (&sb, name + klen, namelen - klen - ksuffixlen);strbuf_addstr (&sb, vstar +1 ); +if (*result) +free (*result);
free(3) can handle NULL pointers; this check is not necessary.
Is it wise to release memory for callers? I'd expect them to be responsible for that. Some of them can pass uninitialized pointers; this is not allowed anymore after the change.
remote.c static char *get_ref_match(const struct refspec *rs, int rs_nr, const struct ref · line 1268
Quoted 9 lines
remote.c +2
-0*result =strbuf_detach (&sb,NULL ); }return ret;@@ -1262,6 +1264,8 @@ static char *get_ref_match(const struct refspec *rs, int rs_nr, const struct ref*/ if (!send_mirror && !starts_with (ref->name,"refs/heads/" ))return NULL ; +if (name) +free (name);
Again, this check is not necessary. If I read the code correctly the pointer could be uninitialized at that point, though, causing free(3) to crash.
Quoted 4 lines
remote.c +0
-0name =xstrdup (ref->name); }if (ret_pat)
Quoted 4 lines · René Scharfe
Again, this check is not necessary. If I read the code correctly the pointer could be uninitialized at that point, though, causing free(3) to crash.
yep, this patch is bogus.