linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dma-buf: fix a memory leak bug
@ 2019-08-16  5:53 Wenwen Wang
  0 siblings, 0 replies; only message in thread
From: Wenwen Wang @ 2019-08-16  5:53 UTC (permalink / raw)
  To: Wenwen Wang
  Cc: Sumit Semwal, Gustavo Padovan, open list:SYNC FILE FRAMEWORK,
	open list:SYNC FILE FRAMEWORK,
	moderated list:DMA BUFFER SHARING FRAMEWORK, open list

In sync_file_merge(), 'fences' is firstly allocated through kcalloc().
Later on, if the size is not sufficient, krealloc() is invoked to
reallocate 'nfences', which is assigned to 'fences'. However, if krealloc()
fails, 'fences' is not deallocated, leading to a memory leak bug.

To fix the above issue, free 'fences' before go to the 'err' label.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
---
 drivers/dma-buf/sync_file.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c
index ee4d1a9..6e2b2d3 100644
--- a/drivers/dma-buf/sync_file.c
+++ b/drivers/dma-buf/sync_file.c
@@ -272,8 +272,10 @@ static struct sync_file *sync_file_merge(const char *name, struct sync_file *a,
 	if (num_fences > i) {
 		nfences = krealloc(fences, i * sizeof(*fences),
 				  GFP_KERNEL);
-		if (!nfences)
+		if (!nfences) {
+			kfree(fences);
 			goto err;
+		}
 
 		fences = nfences;
 	}
-- 
2.7.4


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2019-08-16  5:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-16  5:53 [PATCH] dma-buf: fix a memory leak bug Wenwen Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).