提交 bc1c2caa 编写于 作者: S Stefan Beller 提交者: Junio C Hamano

read-cache.c: free cache entry when refreshing fails

This fixes a memory leak when building the cache entries as
refresh_cache_entry may decide to return NULL, but it does not
free the cache entry structure which was passed in as an argument.
Signed-off-by: NStefan Beller <sbeller@google.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 64a03e97
......@@ -701,7 +701,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,
unsigned int refresh_options)
{
int size, len;
struct cache_entry *ce;
struct cache_entry *ce, *ret;
if (!verify_path(path)) {
error("Invalid path '%s'", path);
......@@ -718,7 +718,13 @@ struct cache_entry *make_cache_entry(unsigned int mode,
ce->ce_namelen = len;
ce->ce_mode = create_ce_mode(mode);
return refresh_cache_entry(ce, refresh_options);
ret = refresh_cache_entry(ce, refresh_options);
if (!ret) {
free(ce);
return NULL;
} else {
return ret;
}
}
int ce_same_name(const struct cache_entry *a, const struct cache_entry *b)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册