Skip to content

Commit 975e329

Browse files
committed
Merge branch 'rs/name-rev-fix-free-after-use' into next
Regression fix for 2.36 where "git name-rev" started to sometimes reference strings after they are freed. * rs/name-rev-fix-free-after-use: Revert "name-rev: release unused name strings"
2 parents acf23a1 + 45a14f5 commit 975e329

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

builtin/name-rev.c

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define CUTOFF_DATE_SLOP 86400
1919

2020
struct rev_name {
21-
char *tip_name;
21+
const char *tip_name;
2222
timestamp_t taggerdate;
2323
int generation;
2424
int distance;
@@ -84,7 +84,7 @@ static int commit_is_before_cutoff(struct commit *commit)
8484

8585
static int is_valid_rev_name(const struct rev_name *name)
8686
{
87-
return name && (name->generation || name->tip_name);
87+
return name && name->tip_name;
8888
}
8989

9090
static struct rev_name *get_commit_rev_name(const struct commit *commit)
@@ -146,20 +146,9 @@ static struct rev_name *create_or_update_name(struct commit *commit,
146146
{
147147
struct rev_name *name = commit_rev_name_at(&rev_names, commit);
148148

149-
if (is_valid_rev_name(name)) {
150-
if (!is_better_name(name, taggerdate, generation, distance, from_tag))
151-
return NULL;
152-
153-
/*
154-
* This string might still be shared with ancestors
155-
* (generation > 0). We can release it here regardless,
156-
* because the new name that has just won will be better
157-
* for them as well, so name_rev() will replace these
158-
* stale pointers when it processes the parents.
159-
*/
160-
if (!name->generation)
161-
free(name->tip_name);
162-
}
149+
if (is_valid_rev_name(name) &&
150+
!is_better_name(name, taggerdate, generation, distance, from_tag))
151+
return NULL;
163152

164153
name->taggerdate = taggerdate;
165154
name->generation = generation;

0 commit comments

Comments
 (0)