[sheepdog] [PATCH] sockfd cache: fix memory leak in sockfd_cache_add()

Liu Yuan namei.unix at gmail.com
Wed Nov 21 09:01:26 CET 2012


From: Liu Yuan <tailai.ly at taobao.com>

When sockfd_cache_insert() fails, we should also release the memory of
fds.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/sockfd_cache.c |    1 +
 1 file changed, 1 insertion(+)

diff --git a/sheep/sockfd_cache.c b/sheep/sockfd_cache.c
index 57122c3..137bbe4 100644
--- a/sheep/sockfd_cache.c
+++ b/sheep/sockfd_cache.c
@@ -273,6 +273,7 @@ void sockfd_cache_add(const struct node_id *nid)
 
 	memcpy(&new->nid, nid, sizeof(struct node_id));
 	if (sockfd_cache_insert(new)) {
+		free(new->fds);
 		free(new);
 		pthread_rwlock_unlock(&sockfd_cache.lock);
 		return;
-- 
1.7.9.5




More information about the sheepdog mailing list