[PATCH] rpmsg: glink: fix memory leak

From: Sudip Mukherjee
Date: Sun Sep 17 2017 - 08:14:54 EST


We missed freeing intent and intent->data on error conditions.

Signed-off-by: Sudip Mukherjee <sudipm.mukherjee@xxxxxxxxx>
---
drivers/rpmsg/qcom_glink_native.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/rpmsg/qcom_glink_native.c b/drivers/rpmsg/qcom_glink_native.c
index 5a5e927..2e64c4d 100644
--- a/drivers/rpmsg/qcom_glink_native.c
+++ b/drivers/rpmsg/qcom_glink_native.c
@@ -640,13 +640,17 @@ qcom_glink_alloc_intent(struct qcom_glink *glink,
return NULL;

intent->data = kzalloc(size, GFP_KERNEL);
- if (!intent->data)
+ if (!intent->data) {
+ kfree(intent);
return NULL;
+ }

spin_lock_irqsave(&channel->intent_lock, flags);
ret = idr_alloc_cyclic(&channel->liids, intent, 1, -1, GFP_ATOMIC);
if (ret < 0) {
spin_unlock_irqrestore(&channel->intent_lock, flags);
+ kfree(intent->data);
+ kfree(intent);
return NULL;
}
spin_unlock_irqrestore(&channel->intent_lock, flags);
--
2.7.4