Skip to contentSkip to conversation

examples/vm_power_manager: fix resource leak

PATCH Applied Rory Sexton 3 participants 3 messages Jul 29, 2020 – Oct 30, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/vm_power_manager: fix resource leak

Fix memory leak where variable oob_enable can go out of scope leaking the storage it points to.

Coverity issue: 337674

Fixes 95f648ff9ee ("examples/vm_power: make branch ratio threshold per core")
---
 examples/vm_power_manager/main.c | 1 +
 1 file changed, 1 insertion(+)
examples/vm_power_manager/main.c +1 -0
index 77797b1e1..0242cca1a 100644
@@ -209,6 +209,7 @@ parse_args(int argc, char **argv)
 			}
 			if (branch_ratio <= 0.0 || branch_ratio > 100.0) {
 				printf("invalid branch ratio specified\n");
+				free(oob_enable);
 				return -1;
 			}
 			for (i = 0; i < ci->core_count; i++) {
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw

Hi Rory,

Quoted 16 lines · Rory Sexton

Fix memory leak where variable oob_enable can go out of scope leaking the storage it points to.

Coverity issue: 337674

Fixes 95f648ff9ee ("examples/vm_power: make branch ratio threshold per core")
---
  examples/vm_power_manager/main.c | 1 +
  1 file changed, 1 insertion(+)
examples/vm_power_manager/main.c +0 -0
index 77797b1e1..0242cca1a 100644

examples/vm_power_manager/main.c parse_args(int argc, char **argv) · line 215

Quoted 7 lines
examples/vm_power_manager/main.c +1 -0
@@ -209,6 +209,7 @@ parse_args(int argc, char **argv)
  			}
  			if (branch_ratio <= 0.0 || branch_ratio > 100.0) {
  				printf("invalid branch ratio specified\n");
+				free(oob_enable);
  				return -1;
  			}
  			for (i = 0; i < ci->core_count; i++) {
Acked-by David Hunt on v1 1/1 Applied
#2 lore raw
In reply to Rory Sexton
Quoted 8 lines · Rory Sexton

Fix memory leak where variable oob_enable can go out of scope leaking the storage it points to.

Coverity issue: 337674

Fixes 95f648ff9ee ("examples/vm_power: make branch ratio threshold per core")

Applied, thanks Rory.

There is another issue in this code.
Previous branches part of the 'b' option handling will break from the parsing loop and have the parse_args() function return the option index where it stopped.
This should instead report a parsing error and have the app fail to initialise.

Something like:

examples/vm_power_manager/main.c +2 -2
index 75d5b5364f..2c394b60fc 100644
@@ -194,7 +194,7 @@ parse_args(int argc, char **argv)
                                       "core-branch-ratio matrix - [%s]\n",
                                                optarg);
                                free(oob_enable);
-                               break;
+                               return -1;
                        }
                        cnt = parse_branch_ratio(optarg, &branch_ratio);
                        if (cnt < 0) {
@@ -202,7 +202,7 @@ parse_args(int argc, char **argv)
                                       "core-branch-ratio matrix - [%s]\n",
                                                optarg);
                                free(oob_enable);
-                               break;
+                               return -1;
                        }
                        if (branch_ratio <= 0.0 || branch_ratio > 100.0) {
                                printf("invalid branch ratio specified\n");

Could you test this and send a followup patch?
Thanks.

Signature · 1 line
David Marchand