diff options
author | David Robillard <d@drobilla.net> | 2024-09-29 19:28:53 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-10-12 14:07:10 -0400 |
commit | 64033dfbb9e9d2fff0df887fc5730c9f97ea4e0d (patch) | |
tree | 69f0383b9df3b74ed46f7467451962fd5e3ccb16 /src | |
parent | dd4fb898df782cb5825eb25d64d0198226b5e7b0 (diff) | |
download | jalv-64033dfbb9e9d2fff0df887fc5730c9f97ea4e0d.tar.gz jalv-64033dfbb9e9d2fff0df887fc5730c9f97ea4e0d.tar.bz2 jalv-64033dfbb9e9d2fff0df887fc5730c9f97ea4e0d.zip |
Handle allocation failure in jack_initialize()
Diffstat (limited to 'src')
-rw-r--r-- | src/jack.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -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); } |