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

Re: [PATCH v7 1/3] tree-walk: learn get_tree_entry_follow_symlinks

From
Jeff King <peff@peff.net>
Date
May 13, 2015, 15:39 UTC
Message-ID
<20150513153944.GA17418@peff.net>
In-Reply-To
<1431481799-23560-2-git-send-email-dturner@twopensource.com>
On Tue, May 12, 2015 at 09:49:57PM -0400, dturner@twopensource.com wrote:
Show 8 quoted lines
> +		} else if (S_ISLNK(*mode)) {
> +			/* Follow a symlink */
> +			unsigned long link_len;
> +			size_t len;
> +			char *contents, *contents_start;
> [...]
> +			contents = read_sha1_file(current_tree_sha1, &type,
> +						  &link_len);
Here we have potentially allocated a buffer for contents...
> +
> +			if (!contents)
> +				goto done;
No need to free here, it's NULL...
Show 7 quoted lines
> +
> +			if (contents[0] == '/') {
> +				strbuf_addstr(result_path, contents);
> +				*mode = 0;
> +				retval = FOUND;
> +				goto done;
> +			}
But here we leak it on "goto done".
Show 15 quoted lines
> +			if (remainder)
> +				len = first_slash - namebuf.buf;
> +			else
> +				len = namebuf.len;
> +
> +			contents_start = contents;
> +
> +			parent = &parents[parents_nr - 1];
> +			init_tree_desc(&t, parent->tree, parent->size);
> +			strbuf_splice(&namebuf, 0, len,
> +				      contents_start, link_len);
> +			if (remainder)
> +				namebuf.buf[link_len] = '/';
> +			free(contents);
> +		}
And this code path calls free(), so it is good.
So I think you just need a free() in the conditional above.
-Peff
Previous: dturner@twopensource.comNext: dturner@twopensource.com
Message 3 of 7 in “[PATCH v7 0/3]”
  1. 0/3 dturner@twopensource.com, May 13, 2015
  2. 1/3 tree-walk: learn get_tree_entry_follow_symlinksdturner@twopensource.com, May 13, 2015
  3. Jeff KingMay 13, 2015
  4. 2/3 sha1_name: get_sha1_with_context learns to follow symlinksdturner@twopensource.com, May 13, 2015
  5. 3/3 cat-file: add --follow-symlinks to --batchdturner@twopensource.com, May 13, 2015
  6. Junio C HamanoMay 13, 2015
  7. Junio C HamanoMay 13, 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.