From: Ingo Molnar Date: Thu, 14 Apr 2005 13:08:29 GMT Subject: [patch] git: clean up add_file_to_cache() in update-cache.c Message-ID: <20050414130829.GB18703@elte.hu> In-Reply-To: <20050414130309.GA18703@elte.hu> this patch cleans up add_file_to_cache() to free up all memory it allocates. This has no significance right now as the only user of add_file_to_cache() die()s immediately in the 'leak' paths - but if the function is ever used without dying then this uncleanliness could lead to a memory leak. Ingo Signed-off-by: Ingo Molnar --- update-cache.c.orig +++ update-cache.c @@ -120,10 +120,17 @@ static int add_file_to_cache(char *path) ce->st_size = st.st_size; ce->namelen = namelen; - if (index_fd(path, namelen, ce, fd, &st) < 0) + if (index_fd(path, namelen, ce, fd, &st) < 0) { + free(ce); return -1; + } - return add_cache_entry(ce, allow_add); + if (add_cache_entry(ce, allow_add)) { + free(ce); + return -1; + } + + return 0; } static int match_data(int fd, void *buffer, unsigned long size)