aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.suppress.cppcheck1
-rw-r--r--src/jack.c14
2 files changed, 10 insertions, 5 deletions
diff --git a/.suppress.cppcheck b/.suppress.cppcheck
index 8845102..d3fb61d 100644
--- a/.suppress.cppcheck
+++ b/.suppress.cppcheck
@@ -4,6 +4,5 @@ constVariablePointer
cstyleCast
invalidscanf
knownConditionTrueFalse
-memleakOnRealloc
normalCheckLevelMaxBranches
unusedStructMember
diff --git a/src/jack.c b/src/jack.c
index 52b78a1..defd8c9 100644
--- a/src/jack.c
+++ b/src/jack.c
@@ -511,17 +511,23 @@ jack_initialize(jack_client_t* const client, const char* const load_init)
int argc = 0;
char** argv = NULL;
char* tok = cmd;
- for (size_t i = 0; i <= cmd_len; ++i) {
+ int err = 0;
+ for (size_t i = 0; !err && i <= cmd_len; ++i) {
if (isspace(cmd[i]) || !cmd[i]) {
- argv = (char**)realloc(argv, sizeof(char*) * ++argc);
+ char** const new_argv = (char**)realloc(argv, sizeof(char*) * ++argc);
+ if (!new_argv) {
+ err = ENOMEM;
+ break;
+ }
+
+ argv = new_argv;
cmd[i] = '\0';
argv[argc - 1] = tok;
tok = cmd + i + 1;
}
}
- const int err = jalv_open(jalv, &argc, &argv);
- if (err) {
+ if (err || (err = jalv_open(jalv, &argc, &argv))) {
jalv_backend_close(jalv);
free(jalv);
}