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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, May 12, 2015 at 09:49:57PM -0400, dturner@xxxxxxxxxxxxxxxx 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]