wimax/i2400m: fix a memory leak bug [Linux 4.9.192]

This Linux kernel change "wimax/i2400m: fix a memory leak bug" is included in the Linux 4.9.192 release. This change is authored by Wenwen Wang <wenwen [at] cs.uga.edu> on Thu Aug 15 15:29:51 2019 -0500. The commit for this change in Linux stable tree is 102a39c (patch) which is from upstream commit 44ef3a0. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 44ef3a0.

wimax/i2400m: fix a memory leak bug

[ Upstream commit 44ef3a03252844a8753479b0cea7f29e4a804bdc ]

In i2400m_barker_db_init(), 'options_orig' is allocated through kstrdup()
to hold the original command line options. Then, the options are parsed.
However, if an error occurs during the parsing process, 'options_orig' is
not deallocated, leading to a memory leak bug. To fix this issue, free
'options_orig' before returning the error.

Signed-off-by: Wenwen Wang <wenwen@cs.uga.edu>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>

There are 4 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 drivers/net/wimax/i2400m/fw.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wimax/i2400m/fw.c b/drivers/net/wimax/i2400m/fw.c
index c9c711d..0e6c665 100644
--- a/drivers/net/wimax/i2400m/fw.c
+++ b/drivers/net/wimax/i2400m/fw.c
@@ -351,13 +351,15 @@ int i2400m_barker_db_init(const char *_options)
            }
            result = i2400m_barker_db_add(barker);
            if (result < 0)
-               goto error_add;
+               goto error_parse_add;
        }
        kfree(options_orig);
    }
    return 0;

+error_parse_add:
 error_parse:
+   kfree(options_orig);
 error_add:
    kfree(i2400m_barker_db);
    return result;

Leave a Reply

Your email address will not be published. Required fields are marked *