prefix_path(): unconditionally free results in the callers
As of d089ebaa
(setup: sanitize absolute and funny paths in
get_pathspec(), 2008-01-28), prefix_path() always returns a
newly allocated string, so callers should free its result.
Additionally, drop the const from variables to which the result of
the prefix_path() is assigned, so they can be free()'d without
having to cast-away the constness.
Signed-off-by: Stefan Beller <sbeller@google.com>
Reviewed-by: Eric Sunshine <sunshine@sunshineco.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
3d4a3ffe64
commit
d7a643b73f
@ -241,7 +241,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
|
||||
/* Check out named files first */
|
||||
for (i = 0; i < argc; i++) {
|
||||
const char *arg = argv[i];
|
||||
const char *p;
|
||||
char *p;
|
||||
|
||||
if (all)
|
||||
die("git checkout-index: don't mix '--all' and explicit filenames");
|
||||
@ -249,8 +249,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
|
||||
die("git checkout-index: don't mix '--stdin' and explicit filenames");
|
||||
p = prefix_path(prefix, prefix_length, arg);
|
||||
checkout_file(p, prefix);
|
||||
if (p < arg || p > arg + strlen(arg))
|
||||
free((char *)p);
|
||||
free(p);
|
||||
}
|
||||
|
||||
if (read_from_stdin) {
|
||||
@ -260,7 +259,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
|
||||
die("git checkout-index: don't mix '--all' and '--stdin'");
|
||||
|
||||
while (strbuf_getline(&buf, stdin, line_termination) != EOF) {
|
||||
const char *p;
|
||||
char *p;
|
||||
if (line_termination && buf.buf[0] == '"') {
|
||||
strbuf_reset(&nbuf);
|
||||
if (unquote_c_style(&nbuf, buf.buf, NULL))
|
||||
@ -269,8 +268,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
|
||||
}
|
||||
p = prefix_path(prefix, prefix_length, buf.buf);
|
||||
checkout_file(p, prefix);
|
||||
if (p < buf.buf || p > buf.buf + buf.len)
|
||||
free((char *)p);
|
||||
free(p);
|
||||
}
|
||||
strbuf_release(&nbuf);
|
||||
strbuf_release(&buf);
|
||||
|
Reference in New Issue
Block a user