git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkout-index.c: Unconditionally free memory
@ 2015-05-01 19:28 Stefan Beller
  2015-05-01 19:33 ` Eric Sunshine
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Stefan Beller @ 2015-05-01 19:28 UTC (permalink / raw)
  To: git, gitster; +Cc: Stefan Beller

It's safe to free the char pointer `p` unconditionally.

The pointer is assigned just 2 lines earlier as a return from
prefix_path, which allocates new memory for its return value.

Then it is used in checkout_file, which passes the pointer on to
cache_name_pos and write_tempfile_record, both of which do not store
the pointer in any permanent record.

So the condition on when to free the pointer is just "always".

Signed-off-by: Stefan Beller <sbeller@google.com>
---
 builtin/checkout-index.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin/checkout-index.c b/builtin/checkout-index.c
index 9ca2da1..e28dc35 100644
--- a/builtin/checkout-index.c
+++ b/builtin/checkout-index.c
@@ -249,8 +249,8 @@ 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((char *)p);
 	}
 
 	if (read_from_stdin) {
-- 
2.4.0.rc3.16.g0ab00b9

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2015-05-03  3:03 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-01 19:28 [PATCH] checkout-index.c: Unconditionally free memory Stefan Beller
2015-05-01 19:33 ` Eric Sunshine
2015-05-01 19:41   ` Eric Sunshine
2015-05-01 19:50 ` Jeff King
2015-05-01 22:33   ` Stefan Beller
2015-05-01 22:39     ` Jeff King
2015-05-01 22:35 ` Stefan Beller
2015-05-01 22:43   ` Jeff King
2015-05-03  2:15     ` Junio C Hamano
2015-05-03  2:30       ` Jeff King
2015-05-03  3:03         ` Junio C Hamano
2015-05-01 23:41   ` Eric Sunshine

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).