Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1309054 > unrolled thread

[PATCH 3/4] mailbox: mailbox-test: Prevent memory leak

Started byLee Jones <lee.jones@linaro.org>
First post2016-01-14 08:20 +0100
Last post2016-01-14 08:20 +0100
Articles 1 — 1 participant

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 3/4] mailbox: mailbox-test: Prevent memory leak Lee Jones <lee.jones@linaro.org> - 2016-01-14 08:20 +0100

#1309054 — [PATCH 3/4] mailbox: mailbox-test: Prevent memory leak

FromLee Jones <lee.jones@linaro.org>
Date2016-01-14 08:20 +0100
Subject[PATCH 3/4] mailbox: mailbox-test: Prevent memory leak
Message-ID<qQKmm-3Em-13@gated-at.bofh.it>
If we set the Signal twice or more, without using it as part of a message,
memory will be re-allocated and the pointer over-written.  Prevent this
potential leak by only allocating memory when there isn't any already.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/mailbox/mailbox-test.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c
index e370aa6..539d475 100644
--- a/drivers/mailbox/mailbox-test.c
+++ b/drivers/mailbox/mailbox-test.c
@@ -58,9 +58,12 @@ static ssize_t mbox_test_signal_write(struct file *filp,
 		return -EINVAL;
 	}
 
-	tdev->signal = kzalloc(MBOX_MAX_SIG_LEN, GFP_KERNEL);
-	if (!tdev->signal)
-		return -ENOMEM;
+	/* Only allocate memory if we need to */
+	if (!tdev->signal) {
+		tdev->signal = kzalloc(MBOX_MAX_SIG_LEN, GFP_KERNEL);
+		if (!tdev->signal)
+			return -ENOMEM;
+	}
 
 	if (copy_from_user(tdev->signal, userbuf, count)) {
 		kfree(tdev->signal);
-- 
1.9.1

[toc] | [standalone]


Back to top | Article view | linux.kernel


csiph-web