aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-09-29 19:30:13 -0400
committerDavid Robillard <d@drobilla.net>2024-10-12 14:07:10 -0400
commit8c7b645094d026367cecadb05f66a49800dd4235 (patch)
tree1c0819e5fba57222ad4749ba670458de7da3eb86 /src
parent64033dfbb9e9d2fff0df887fc5730c9f97ea4e0d (diff)
downloadjalv-8c7b645094d026367cecadb05f66a49800dd4235.tar.gz
jalv-8c7b645094d026367cecadb05f66a49800dd4235.tar.bz2
jalv-8c7b645094d026367cecadb05f66a49800dd4235.zip
Handle realloc failure everywhere
Diffstat (limited to 'src')
-rw-r--r--src/control.c7
-rw-r--r--src/jalv.c8
-rw-r--r--src/jalv_console.c15
3 files changed, 22 insertions, 8 deletions
diff --git a/src/control.c b/src/control.c
index 7150032..68a5bfb 100644
--- a/src/control.c
+++ b/src/control.c
@@ -170,10 +170,13 @@ new_property_control(LilvWorld* const world,
void
add_control(Controls* controls, ControlID* control)
{
- controls->controls = (ControlID**)realloc(
+ ControlID** const new_controls = (ControlID**)realloc(
controls->controls, (controls->n_controls + 1) * sizeof(ControlID*));
- controls->controls[controls->n_controls++] = control;
+ if (new_controls) {
+ controls->controls = new_controls;
+ controls->controls[controls->n_controls++] = control;
+ }
}
ControlID*
diff --git a/src/jalv.c b/src/jalv.c
index c6055ae..24a1008 100644
--- a/src/jalv.c
+++ b/src/jalv.c
@@ -751,8 +751,12 @@ jalv_update(Jalv* jalv)
zix_ring_read(jalv->plugin_to_ui, &ev, sizeof(ev));
// Resize read buffer if necessary
- jalv->ui_event_buf = realloc(jalv->ui_event_buf, ev.size);
- void* const buf = jalv->ui_event_buf;
+ void* const buf = realloc(jalv->ui_event_buf, ev.size);
+ if (!buf) {
+ return 12;
+ }
+
+ jalv->ui_event_buf = buf;
// Read event body
zix_ring_read(jalv->plugin_to_ui, buf, ev.size);
diff --git a/src/jalv_console.c b/src/jalv_console.c
index 635b668..3cbd76c 100644
--- a/src/jalv_console.c
+++ b/src/jalv_console.c
@@ -128,10 +128,17 @@ jalv_frontend_init(int* argc, char*** argv, JalvOptions* opts)
fprintf(stderr, "Missing argument for -c\n");
return 1;
}
- opts->controls =
- (char**)realloc(opts->controls, (++n_controls + 1) * sizeof(char*));
- opts->controls[n_controls - 1] = (*argv)[a];
- opts->controls[n_controls] = NULL;
+
+ char** new_controls =
+ (char**)realloc(opts->controls, (n_controls + 2) * sizeof(char*));
+ if (!new_controls) {
+ fprintf(stderr, "Out of memory\n");
+ return 12;
+ }
+
+ opts->controls = new_controls;
+ opts->controls[n_controls++] = (*argv)[a];
+ opts->controls[n_controls] = NULL;
} else if ((*argv)[a][1] == 'i') {
opts->non_interactive = true;
} else if ((*argv)[a][1] == 'd') {