Commit bdf79c55 authored by Hanspeter Portner's avatar Hanspeter Portner

api: free tlsf-alloc'd memory with fail in stash.

parent 1707eca6
Pipeline #26345262 passed with stages
in 4 minutes and 6 seconds
......@@ -472,8 +472,8 @@ _sink_rt(LV2_Atom_Forge_Sink_Handle handle, const void *buf, uint32_t size)
while(new_offset > new_size)
new_size <<= 1;
assert(ser->vm);
if(!(ser->buf = moony_rt_realloc(ser->vm, ser->buf, ser->size, new_size)))
assert(ser->data);
if(!(ser->buf = moony_rt_realloc(ser->data, ser->buf, ser->size, new_size)))
return 0; // realloc failed
ser->size = new_size;
......@@ -534,23 +534,26 @@ _stash(lua_State *L)
lframe->last.frames = 0;
lframe->forge = &moony->stash_forge;
atom_ser_t ser = {
.vm = moony->vm,
.size = 1024,
.offset = 0
};
ser.buf = moony_rt_alloc(moony->vm, ser.size);
atom_ser_t *ser = &moony->vm->ser;
ser->data = moony->vm;
ser->size = 1024;
ser->offset = 0;
ser->buf = moony_rt_alloc(moony->vm, ser->size);
if(ser.buf)
if(ser->buf)
{
memset(ser.buf, 0x0, sizeof(LV2_Atom));
memset(ser->buf, 0x0, sizeof(LV2_Atom));
lv2_atom_forge_set_sink(lframe->forge, _sink_rt, _deref, &ser);
lv2_atom_forge_set_sink(lframe->forge, _sink_rt, _deref, ser);
lua_call(L, 1, 0);
LV2_Atom *atom = (LV2_Atom *)ser.buf;
LV2_Atom *atom = (LV2_Atom *)ser->buf;
moony->stash_atom = atom;
moony->stash_size = ser.size;
moony->stash_size = ser->size;
// invalidate ser_atom
ser->size = 0;
ser->buf = NULL;
}
}
else
......@@ -720,7 +723,7 @@ _state_save(LV2_Handle instance,
(void)status; //TODO check status
atom_ser_t ser = {
.vm = NULL,
.data = NULL,
.size = 1024,
.offset = 0
};
......
......@@ -24,7 +24,7 @@ _lstash__gc(lua_State *L)
atom_ser_t *ser = &lstash->ser;
if(ser->buf)
moony_rt_free(ser->vm, ser->buf, ser->size);
moony_rt_free(ser->data, ser->buf, ser->size);
return 0;
}
......@@ -82,7 +82,7 @@ _lstash(lua_State *L)
// initialize memory pool
atom_ser_t *ser = &lstash->ser;
ser->vm = vm;
ser->data = vm;
ser->size = 1024;
ser->offset = 0; // reset stash pointer
ser->buf = moony_rt_alloc(vm, ser->size);
......
......@@ -254,6 +254,9 @@ moony_vm_free(moony_vm_t *vm)
if(vm->L)
lua_close(vm->L);
if(vm->ser.buf)
moony_rt_free(vm, vm->ser.buf, vm->ser.size);
vm->used = 0;
for(int i=(MOONY_POOL_NUM-1); i>=0; i--)
......
......@@ -49,6 +49,8 @@ struct _moony_vm_t {
bool trace_out;
bool trace_overflow;
char trace [MOONY_MAX_TRACE_LEN];
atom_ser_t ser;
};
enum _moony_job_enum_t {
......
......@@ -48,6 +48,18 @@
#include <lv2/lv2plug.in/ns/extensions/ui/ui.h>
#include <lv2/lv2plug.in/ns/extensions/units/units.h>
typedef struct _atom_ser_t atom_ser_t;
struct _atom_ser_t {
void *data; // e.g. use rt-memory pool?
uint32_t size;
union {
uint8_t *buf;
const LV2_Atom *atom;
};
uint32_t offset;
};
#include <api_vm.h>
#include <osc.lv2/osc.h>
#include <xpress.lv2/xpress.h>
......@@ -459,16 +471,4 @@ _sink_non_rt(LV2_Atom_Forge_Sink_Handle handle, const void *buf, uint32_t size);
LV2_Atom *
_deref(LV2_Atom_Forge_Sink_Handle handle, LV2_Atom_Forge_Ref ref);
typedef struct _atom_ser_t atom_ser_t;
struct _atom_ser_t {
moony_vm_t *vm; // use rt-memory pool?
uint32_t size;
union {
uint8_t *buf;
const LV2_Atom *atom;
};
uint32_t offset;
};
#endif // _MOONY_H
......@@ -2907,7 +2907,7 @@ instantiate(const LV2UI_Descriptor *descriptor, const char *plugin_uri,
*(intptr_t *)widget = nk_pugl_init(&handle->win);
nk_pugl_show(&handle->win);
handle->ser.vm = NULL;
handle->ser.data = NULL;
handle->ser.size = 1024;
handle->ser.buf = malloc(1024);
handle->ser.offset = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment