diff mbox series

[BlueZ,02/12] shared/shell: Free w.we_wordv on early function exit

Message ID 20240704102617.1132337-3-hadess@hadess.net
State New
Headers show
Series Fix a number of static analysis issues #5 | expand

Commit Message

Bastien Nocera July 4, 2024, 10:24 a.m. UTC
Error: RESOURCE_LEAK (CWE-772): [#def38] [important]
bluez-5.76/src/shared/shell.c:519:2: alloc_arg: "parse_args" allocates memory that is stored into "w.we_wordv".
bluez-5.76/src/shared/shell.c:523:3: leaked_storage: Variable "w" going out of scope leaks the storage "w.we_wordv" points to.
521|			"Unable to parse mandatory command arguments: %s", man );
522|		free(man);
523|->		return -EINVAL;
524|	}
525|

Error: RESOURCE_LEAK (CWE-772): [#def39] [important]
bluez-5.76/src/shared/shell.c:539:2: alloc_arg: "parse_args" allocates memory that is stored into "w.we_wordv".
bluez-5.76/src/shared/shell.c:543:3: leaked_storage: Variable "w" going out of scope leaks the storage "w.we_wordv" points to.
541|			"Unable to parse optional command arguments: %s", opt);
542|		free(opt);
543|->		return -EINVAL;
544|	}
545|
---
 src/shared/shell.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/src/shared/shell.c b/src/shared/shell.c
index add4fa131c7a..878be140c336 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -525,6 +525,7 @@  static int cmd_exec(const struct bt_shell_menu_entry *entry,
 		print_text(COLOR_HIGHLIGHT,
 			"Unable to parse mandatory command arguments: %s", man );
 		free(man);
+		wordfree(&w);
 		return -EINVAL;
 	}
 
@@ -545,6 +546,7 @@  optional:
 		print_text(COLOR_HIGHLIGHT,
 			"Unable to parse optional command arguments: %s", opt);
 		free(opt);
+		wordfree(&w);
 		return -EINVAL;
 	}