Drivers: hv: don't leak memory in vmbus_establish_gpadl()
authorVitaly Kuznetsov <vkuznets@redhat.com>
Sat, 4 Jun 2016 00:09:24 +0000 (17:09 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 31 Aug 2016 11:05:41 +0000 (13:05 +0200)
In some cases create_gpadl_header() allocates submessages but we never
free them.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hv/channel.c

index 2b109e8a8c97809f874e887228a31b272f8aa608..a68830c848e4763c1c164b2fd159df1f4b9b9d26 100644 (file)
@@ -388,7 +388,7 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
        struct vmbus_channel_gpadl_header *gpadlmsg;
        struct vmbus_channel_gpadl_body *gpadl_body;
        struct vmbus_channel_msginfo *msginfo = NULL;
-       struct vmbus_channel_msginfo *submsginfo;
+       struct vmbus_channel_msginfo *submsginfo, *tmp;
        struct list_head *curr;
        u32 next_gpadl_handle;
        unsigned long flags;
@@ -445,6 +445,10 @@ cleanup:
        spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags);
        list_del(&msginfo->msglistentry);
        spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags);
+       list_for_each_entry_safe(submsginfo, tmp, &msginfo->submsglist,
+                                msglistentry) {
+               kfree(submsginfo);
+       }
 
        kfree(msginfo);
        return ret;