From: Jeff King <peff@peff.net>
To: dturner@twopensource.com
Cc: git@vger.kernel.org, David Turner <dturner@twitter.com>
Subject: Re: [PATCH v7 1/3] tree-walk: learn get_tree_entry_follow_symlinks
Date: Wed, 13 May 2015 11:39:45 -0400 [thread overview]
Message-ID: <20150513153944.GA17418@peff.net> (raw)
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:
> + } 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...
> +
> + if (contents[0] == '/') {
> + strbuf_addstr(result_path, contents);
> + *mode = 0;
> + retval = FOUND;
> + goto done;
> + }
But here we leak it on "goto done".
> + 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
next prev parent reply other threads:[~2015-05-13 15:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-13 1:49 [PATCH v7 0/3] dturner
2015-05-13 1:49 ` [PATCH v7 1/3] tree-walk: learn get_tree_entry_follow_symlinks dturner
2015-05-13 15:39 ` Jeff King [this message]
2015-05-13 1:49 ` [PATCH v7 2/3] sha1_name: get_sha1_with_context learns to follow symlinks dturner
2015-05-13 1:49 ` [PATCH v7 3/3] cat-file: add --follow-symlinks to --batch dturner
2015-05-13 3:57 ` Junio C Hamano
2015-05-13 5:51 ` [PATCH v7 0/3] Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150513153944.GA17418@peff.net \
--to=peff@peff.net \
--cc=dturner@twitter.com \
--cc=dturner@twopensource.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.