From 4d1649e313da9d658bb6c653b3f4a2c6d983299d Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 22 Jan 2013 05:05:29 +0000 Subject: Use a dynamically allocated buffer for reading from plugin=>UI ring to avoid blowing the stack if a plugin sends very large updates to the UI. git-svn-id: http://svn.drobilla.net/lad/trunk/jalv@5003 a436a847-0d15-0410-975c-d299462d15a1 --- src/jalv.c | 10 +++++++++- src/jalv_internal.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/jalv.c b/src/jalv.c index 70cfb2c..9668d2c 100644 --- a/src/jalv.c +++ b/src/jalv.c @@ -732,11 +732,18 @@ jalv_emit_ui_events(Jalv* jalv) ControlChange ev; const size_t space = jack_ringbuffer_read_space(jalv->plugin_events); for (size_t i = 0; i < space; i += sizeof(ev) + ev.size) { + // Read event header to get the size jack_ringbuffer_read(jalv->plugin_events, (char*)&ev, sizeof(ev)); - char buf[ev.size]; + + // Resize read buffer if necessary + jalv->ui_event_buf = realloc(jalv->ui_event_buf, ev.size); + void* const buf = jalv->ui_event_buf; + + // Read event body jack_ringbuffer_read(jalv->plugin_events, buf, ev.size); if (jalv->opts.dump && ev.protocol == jalv->urids.atom_eventTransfer) { + // Dump event in Turtle to the console SerdNode s = serd_node_from_string(SERD_BLANK, USTR("msg")); SerdNode p = serd_node_from_string(SERD_URI, USTR(NS_RDF "value")); LV2_Atom* atom = (LV2_Atom*)buf; @@ -1130,6 +1137,7 @@ main(int argc, char** argv) remove(jalv.temp_dir); free(jalv.temp_dir); + free(jalv.ui_event_buf); return 0; } diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 64c4373..b8bf649 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -162,6 +162,7 @@ typedef struct { jack_client_t* jack_client; ///< Jack client jack_ringbuffer_t* ui_events; ///< Port events from UI jack_ringbuffer_t* plugin_events; ///< Port events from plugin + void* ui_event_buf; ///< Buffer for reading UI port events JalvWorker worker; ///< Worker thread implementation ZixSem* done; ///< Exit semaphore ZixSem paused; ///< Paused signal from process thread -- cgit v1.2.1