last-modified: fix memory leak when more than one commit is given
When more than one commit is given, the function populate_paths_from_revs() leaks a `struct pathspec`. Plug it. Signed-off-by: Toon Claes <toon@iotcl.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Toon Claes committed
Jan 30, 2026 at 15:26 UTC
e2505ec170bc0861c3b902bc9763416c5f222455
1 file changed
+8
-4
builtin/last-modified.c
+8
-4
@@ -123,7 +123,7 @@ static void add_path_from_diff(struct diff_queue_struct *q,
123
124
static int populate_paths_from_revs(struct last_modified *lm)
125
{
126
- int num_interesting = 0;
126
+ int num_interesting = 0, ret = 0;
127
struct diff_options diffopt;
128
129
/*
@@ -145,16 +145,20 @@ static int populate_paths_from_revs(struct last_modified *lm)
145
if (obj->item->flags & UNINTERESTING)
146
continue;
147
148
- if (num_interesting++)
149
- return error(_("last-modified can only operate on one commit at a time"));
148
+ if (num_interesting++) {
149
+ ret = error(_("last-modified can only operate on one commit at a time"));
150
+ goto out;
151
+ }
152
153
diff_tree_oid(lm->rev.repo->hash_algo->empty_tree,
154
&obj->item->oid, "", &diffopt);
155
diff_flush(&diffopt);
156
}
157
+
158
+out:
159
clear_pathspec(&diffopt.pathspec);
160
157
- return 0;
161
+ return ret;
162
}
163
164
static void last_modified_emit(struct last_modified *lm,