Skip to content

Commit d292bfa

Browse files
Ramsay Jonesgitster
authored andcommitted
Call git_pathdup() rather than xstrdup(git_path("..."))
In addition to updating the two xstrdup(git_path("...")) call sites with git_pathdup(), we also fix a memory leak by freeing the memory allocated to the ADD_EDIT.patch 'file' in the edit_patch() function. Signed-off-by: Ramsay Jones <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5c44252 commit d292bfa

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

bisect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ static int check_ancestors(const char *prefix)
833833
*/
834834
static void check_good_are_ancestors_of_bad(const char *prefix, int no_checkout)
835835
{
836-
char *filename = xstrdup(git_path("BISECT_ANCESTORS_OK"));
836+
char *filename = git_pathdup("BISECT_ANCESTORS_OK");
837837
struct stat st;
838838
int fd;
839839

builtin/add.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ int interactive_add(int argc, const char **argv, const char *prefix, int patch)
260260

261261
static int edit_patch(int argc, const char **argv, const char *prefix)
262262
{
263-
char *file = xstrdup(git_path("ADD_EDIT.patch"));
263+
char *file = git_pathdup("ADD_EDIT.patch");
264264
const char *apply_argv[] = { "apply", "--recount", "--cached",
265265
NULL, NULL };
266266
struct child_process child;
@@ -303,6 +303,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix)
303303
die (_("Could not apply '%s'"), file);
304304

305305
unlink(file);
306+
free(file);
306307
return 0;
307308
}
308309

0 commit comments

Comments
 (0)