diff mbox series

[ethtool,2/2] netlink: fix memory leak

Message ID 20200924192758.577595-2-ivecera@redhat.com
State New
Headers show
Series None | expand

Commit Message

Ivan Vecera Sept. 24, 2020, 7:27 p.m. UTC
Potentially allocated memory allocated for mask is not freed when
the allocation for value fails.

Fixes: 81a30f416ec7 ("netlink: add bitset command line parser handlers")

Cc: Michal Kubecek <mkubecek@suse.cz>
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
 netlink/parser.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Michal Kubecek Sept. 28, 2020, 3:37 p.m. UTC | #1
On Thu, Sep 24, 2020 at 09:27:58PM +0200, Ivan Vecera wrote:
> Potentially allocated memory allocated for mask is not freed when
> the allocation for value fails.
> 
> Fixes: 81a30f416ec7 ("netlink: add bitset command line parser handlers")
> 
> Cc: Michal Kubecek <mkubecek@suse.cz>
> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
> ---

Applied, thank you.

Michal

>  netlink/parser.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/netlink/parser.c b/netlink/parser.c
> index c5a368a65a7a..3b25f5d5a88e 100644
> --- a/netlink/parser.c
> +++ b/netlink/parser.c
> @@ -630,8 +630,10 @@ static int parse_numeric_bitset(struct nl_context *nlctx, uint16_t type,
>  	}
>  
>  	value = calloc(nwords, sizeof(uint32_t));
> -	if (!value)
> +	if (!value) {
> +		free(mask);
>  		return -ENOMEM;
> +	}
>  	ret = __parse_num_string(arg, len1, value, force_hex1);
>  	if (ret < 0) {
>  		parser_err_invalid_value(nlctx, arg);
> -- 
> 2.26.2
>
diff mbox series

Patch

diff --git a/netlink/parser.c b/netlink/parser.c
index c5a368a65a7a..3b25f5d5a88e 100644
--- a/netlink/parser.c
+++ b/netlink/parser.c
@@ -630,8 +630,10 @@  static int parse_numeric_bitset(struct nl_context *nlctx, uint16_t type,
 	}
 
 	value = calloc(nwords, sizeof(uint32_t));
-	if (!value)
+	if (!value) {
+		free(mask);
 		return -ENOMEM;
+	}
 	ret = __parse_num_string(arg, len1, value, force_hex1);
 	if (ret < 0) {
 		parser_err_invalid_value(nlctx, arg);