diff mbox series

[v4,15/19] pull: trivial memory fix

Message ID 20201208002648.1370414-16-felipe.contreras@gmail.com (mailing list archive)
State New, archived
Headers show
Series [v4,01/19] doc: pull: explain what is a fast-forward | expand

Commit Message

Felipe Contreras Dec. 8, 2020, 12:26 a.m. UTC
The opt_ff variable is supposed to have an allocated string (strdup), we
can't just overwrite it with a const char *.

Functionally it doesn't matter, since after this point opt_ff is never
freed, only accessed, but still...

It's better to be consistent.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 builtin/pull.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/builtin/pull.c b/builtin/pull.c
index addb454e63..118fbdeb62 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -1056,7 +1056,8 @@  int cmd_pull(int argc, const char **argv, const char *prefix)
 
 		if (can_ff) {
 			/* we can fast-forward this without invoking rebase */
-			opt_ff = "--ff-only";
+			free(opt_ff);
+			opt_ff = xstrdup_or_null("--ff-only");
 			ret = run_merge();
 		} else {
 			ret = run_rebase(&newbase, &upstream);