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

[Outreachy] Return value before or after free()?

From
Miriam R. <mirucam@gmail.com>
Date
Jan 6, 2020, 21:15 UTC
Message-ID
<CAN7CjDDBA0ZoCG9aaQf5rg3gxqny=EjR6v6jE1mnxvUJQSF_0Q@mail.gmail.com>

Dear all, in run-command.c file `exists_in_PATH()` function does this:

static int exists_in_PATH(const char *file) { char *r = locate_in_PATH(file); free(r); return r != NULL; }

I wonder if it is correct to do return r != NULL; after free(r);
Could be this version more readable? :

static int exists_in_PATH(const char *file) { char *r = locate_in_PATH(file); int res = (r != NULL); free(r); return res; }

Could you please give me your feedback?
Thank you!

Best, Miriam.

Next: Jeff King
Message 1 of 7 in “[Outreachy] Return value before or after free()?”
  1. Miriam R.Jan 6, 2020
  2. Jeff KingJan 6, 2020
  3. Jonathan NiederJan 6, 2020
  4. Andreas SchwabJan 6, 2020
  5. brian m. carlsonJan 7, 2020
  6. brian m. carlsonJan 7, 2020
  7. Miriam R.Jan 7, 2020

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.