Skip to content

Commit

Permalink
properly free sig_info based on previous signal count
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-wes committed Oct 18, 2024
1 parent 73ac4e4 commit e691179
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 5 additions & 4 deletions pdlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,9 +742,8 @@ static void pdlua_free( t_pdlua *o /**< The object to destruct. */)
PDLUA_DEBUG("pdlua_free: end. stack top %d", lua_gettop(__L()));

// Free sig_info if it exists
// FIXME: necessary?
if (o->sig_info) {
freebytes(o->sig_info, (o->siginlets + o->sigoutlets) * sizeof(t_pdlua_siginfo));
freebytes(o->sig_info, o->sig_count * sizeof(t_pdlua_siginfo));
o->sig_info = NULL;
}

Expand Down Expand Up @@ -1186,13 +1185,14 @@ static void pdlua_dsp(t_pdlua *x, t_signal **sp){

PDLUA_DEBUG("pdlua_dsp: end. stack top %d", lua_gettop(__L()));

// Free existing sig_info if it exists
// Free existing sig_info if it exists, using the old sig_count
if (x->sig_info) {
freebytes(x->sig_info, sum * sizeof(t_pdlua_siginfo));
freebytes(x->sig_info, x->sig_count * sizeof(t_pdlua_siginfo));
x->sig_info = NULL;
}

x->sig_info = (t_pdlua_siginfo *)getbytes(sum * sizeof(t_pdlua_siginfo));
x->sig_count = sum;

for (int i = 0; i < sum; i++) {
x->sig_info[i].vec = sp[i]->s_vec;
Expand Down Expand Up @@ -1451,6 +1451,7 @@ static int pdlua_object_new(lua_State *L)
o->pdlua_class_gfx = c_gfx;
o->sp = NULL;
o->sig_info = NULL;
o->sig_count = 0;

o->gfx.width = 80;
o->gfx.height = 80;
Expand Down
7 changes: 4 additions & 3 deletions pdlua.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ typedef struct _pdlua_gfx
#endif
} t_pdlua_gfx;


/** Structure to hold signal information. */
typedef struct pdlua_siginfo
typedef struct
{
t_float *vec; // Signal vector
int nchans; // Number of channels
} t_pdlua_siginfo;


/** Pd object data. */
typedef struct pdlua
{
Expand All @@ -69,6 +69,8 @@ typedef struct pdlua
t_inlet **in;
int outlets; // Number of outlets.
t_outlet **out; // The outlets themselves.
t_pdlua_siginfo *sig_info; // Array of signal info structures for perform function.
int sig_count; // Total number of signal iolets for sig_info memory management.
int siginlets; // Number of signal inlets.
int sigoutlets; // Number of signal outlets.
int sig_warned; // Flag for perform signal errors.
Expand All @@ -78,7 +80,6 @@ typedef struct pdlua
t_pdlua_gfx gfx; // Holds state for graphics.
t_class *pdlua_class; // Holds our class pointer.
t_class *pdlua_class_gfx; // Holds our gfx class pointer.
t_pdlua_siginfo *sig_info; // Array of signal info structures
t_signal **sp; // Array of signal pointers for multichannel audio.
} t_pdlua;

Expand Down

0 comments on commit e691179

Please sign in to comment.