aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicholas Vinson <nvinson234@gmail.com>2023-04-30 18:50:51 -0400
committerMichal Kubecek <mkubecek@suse.cz>2023-05-08 00:11:26 +0200
commit7de97fb998689dfae18b045d5008af7cd932648e (patch)
treec5d429b144f5241ed4bb78a4235b9ca026b9e373
parent77599cf0411072591deafe0e567dbbe1eb21b0c8 (diff)
downloadethtool-7de97fb998689dfae18b045d5008af7cd932648e.tar.gz
Fix reported memory leak.
Found via gcc -fanalyzer. In the function nl_sfeatures() malloc() is called to allocate a block of memory; however, that memory block is never explictily freed. Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
-rw-r--r--netlink/features.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/netlink/features.c b/netlink/features.c
index a93f3e7..5711ff4 100644
--- a/netlink/features.c
+++ b/netlink/features.c
@@ -534,24 +534,36 @@ int nl_sfeatures(struct cmd_context *ctx)
nlctx->devname = ctx->devname;
ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_FEATURES_SET,
NLM_F_REQUEST | NLM_F_ACK);
- if (ret < 0)
+ if (ret < 0) {
+ free(sfctx);
return 2;
+ }
if (ethnla_fill_header(msgbuff, ETHTOOL_A_FEATURES_HEADER, ctx->devname,
- ETHTOOL_FLAG_COMPACT_BITSETS))
+ ETHTOOL_FLAG_COMPACT_BITSETS)) {
+ free(sfctx);
return -EMSGSIZE;
+ }
ret = fill_sfeatures_bitmap(nlctx, feature_names);
- if (ret < 0)
+ if (ret < 0) {
+ free(sfctx);
return ret;
+ }
ret = nlsock_sendmsg(nlsk, NULL);
- if (ret < 0)
+ if (ret < 0) {
+ free(sfctx);
return 92;
+ }
ret = nlsock_process_reply(nlsk, sfeatures_reply_cb, nlctx);
if (sfctx->nothing_changed) {
fprintf(stderr, "Could not change any device features\n");
+ free(sfctx);
return nlctx->exit_code ?: 1;
}
- if (ret == 0)
+ if (ret == 0) {
+ free(sfctx);
return 0;
+ }
+ free(sfctx);
return nlctx->exit_code ?: 92;
}