fix: replace real-time unsafe malloc with stack buffers in process_callback
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
16
engine.c
16
engine.c
@@ -1,5 +1,7 @@
|
|||||||
#include "engine.h"
|
#include "engine.h"
|
||||||
#include "carla.h"
|
#include "carla.h"
|
||||||
|
|
||||||
|
#define MAX_NFRAMES 8192
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -125,13 +127,11 @@ static int process_callback(jack_nframes_t nframes, void *arg) {
|
|||||||
for (int ch = 0; ch < MAX_CHANNELS; ch++) {
|
for (int ch = 0; ch < MAX_CHANNELS; ch++) {
|
||||||
memset(audio_out[ch], 0, sizeof(jack_default_audio_sample_t) * nframes);
|
memset(audio_out[ch], 0, sizeof(jack_default_audio_sample_t) * nframes);
|
||||||
|
|
||||||
// Create temporary buffer for rack processing
|
// Use stack-allocated buffers (max MAX_NFRAMES samples)
|
||||||
float *rack_in = malloc(nframes * sizeof(float));
|
float rack_in[MAX_NFRAMES];
|
||||||
float *rack_out = malloc(nframes * sizeof(float));
|
float rack_out[MAX_NFRAMES];
|
||||||
|
if (nframes > MAX_NFRAMES) {
|
||||||
if (!rack_in || !rack_out) {
|
// Should never happen with JACK, but guard
|
||||||
free(rack_in);
|
|
||||||
free(rack_out);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,8 +164,6 @@ static int process_callback(jack_nframes_t nframes, void *arg) {
|
|||||||
// Copy to output
|
// Copy to output
|
||||||
memcpy(audio_out[ch], rack_out, nframes * sizeof(jack_default_audio_sample_t));
|
memcpy(audio_out[ch], rack_out, nframes * sizeof(jack_default_audio_sample_t));
|
||||||
|
|
||||||
free(rack_in);
|
|
||||||
free(rack_out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user