git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] checkout-index.c: Unconditionally free memory

From
Eric Sunshine <sunshine@sunshineco.com>
Date
May 1, 2015, 19:33 UTC
Message-ID
<CAPig+cQr5wQ6nfy90+SWyFFv0Neq4oJiEtur4cBJNGHNKXhZrQ@mail.gmail.com>
In-Reply-To
<1430508507-14016-1-git-send-email-sbeller@google.com>
On Fri, May 1, 2015 at 3:28 PM, Stefan Beller <sbeller@google.com> wrote:
Show 10 quoted lines
> 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".
Why doesn't the 'p' in the 'while' loop just below deserve the same treatment?
Show 24 quoted lines
> Signed-off-by: Stefan Beller <sbeller@google.com>
> ---
> 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
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous: Stefan BellerNext: Eric Sunshine
Message 2 of 12 in “checkout-index.c: Unconditionally free memory”
  1. checkout-index.c: Unconditionally free memoryStefan Beller, May 1, 2015
  2. Eric SunshineMay 1, 2015
  3. Eric SunshineMay 1, 2015
  4. Jeff KingMay 1, 2015
  5. Stefan BellerMay 1, 2015
  6. Jeff KingMay 1, 2015
  7. checkout-index.c: Unconditionally free memoryStefan Beller, May 1, 2015
  8. Jeff KingMay 1, 2015
  9. Junio C HamanoMay 3, 2015
  10. Jeff KingMay 3, 2015
  11. Junio C HamanoMay 3, 2015
  12. Eric SunshineMay 1, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.