Skip to content

Commit 789e98d

Browse files
committed
Merge branch 'jc/plug-fmt-merge-msg-leak'
* jc/plug-fmt-merge-msg-leak: fmt-merge-msg: plug small leak of commit buffer
2 parents eb10a85 + 1154aa4 commit 789e98d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

builtin/fmt-merge-msg.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,14 @@ static void add_branch_desc(struct strbuf *out, const char *name)
223223

224224
#define util_as_integral(elem) ((intptr_t)((elem)->util))
225225

226-
static void record_person(int which, struct string_list *people,
227-
struct commit *commit)
226+
static void record_person_from_buf(int which, struct string_list *people,
227+
const char *buffer)
228228
{
229-
const char *buffer;
230229
char *name_buf, *name, *name_end;
231230
struct string_list_item *elem;
232231
const char *field;
233232

234233
field = (which == 'a') ? "\nauthor " : "\ncommitter ";
235-
buffer = get_commit_buffer(commit, NULL);
236234
name = strstr(buffer, field);
237235
if (!name)
238236
return;
@@ -245,7 +243,6 @@ static void record_person(int which, struct string_list *people,
245243
if (name_end < name)
246244
return;
247245
name_buf = xmemdupz(name, name_end - name + 1);
248-
unuse_commit_buffer(commit, buffer);
249246

250247
elem = string_list_lookup(people, name_buf);
251248
if (!elem) {
@@ -256,6 +253,15 @@ static void record_person(int which, struct string_list *people,
256253
free(name_buf);
257254
}
258255

256+
257+
static void record_person(int which, struct string_list *people,
258+
struct commit *commit)
259+
{
260+
const char *buffer = get_commit_buffer(commit, NULL);
261+
record_person_from_buf(which, people, buffer);
262+
unuse_commit_buffer(commit, buffer);
263+
}
264+
259265
static int cmp_string_list_util_as_integral(const void *a_, const void *b_)
260266
{
261267
const struct string_list_item *a = a_, *b = b_;

0 commit comments

Comments
 (0)