From 13d043652ade404662f846f3861914cd5171847e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Wed, 22 Feb 2012 13:08:43 +0000 Subject: never ever mix calloc with freebytes memory allocated by libc (e.g. using 'malloc') MUST NOT be freed using freebytes() since the latter might use a different free() implementation. on w32 this is quite common, depending on how Pd is compiled, and how the external is compiled svn path=/trunk/externals/iem/iemmatrix/; revision=16028 --- src/mtx_conv.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/mtx_conv.c b/src/mtx_conv.c index 43655f4..de1e260 100644 --- a/src/mtx_conv.c +++ b/src/mtx_conv.c @@ -11,7 +11,6 @@ * WARRANTIES, see the file, "LICENSE.txt," in this distribution. * */ - #include "iemmatrix.h" #include @@ -54,28 +53,28 @@ static void getTFloatMatrix (int rows, int columns, t_float ***mtx, t_float **ar if (!size) return; - if (*array=ptr=(t_float *)calloc(sizeof(t_float),size)) { - if (*mtx=dptr=(t_float **)calloc(sizeof(t_float *),rows)) { + if (*array=ptr=(t_float *)calloc(size, sizeof(t_float))) { + if (*mtx=dptr=(t_float **)calloc(rows, sizeof(t_float *))) { for(;rows-- ; ptr+=columns) { *dptr++ = ptr; } } else { - freebytes (*array,sizeof(t_float)*size); + free (*array); array=0; } } } -static void deleteTFloatMatrix (int rows, int columns, t_float ***mtx, t_float **array) +static void deleteTFloatMatrix (int rows, int columns, t_float ***mtx, t_float **myarray) { int size = rows*columns; - if (*mtx) - freebytes (*mtx, sizeof(t_float*) * columns); - if (*array) - freebytes (*array, sizeof(t_float) * size); + free (*mtx); + + if (*myarray) + free (*myarray); *mtx=0; - *array=0; + *myarray=0; } @@ -85,7 +84,7 @@ static void deleteMTXConv (MTXConv *mtx_conv_obj) deleteTFloatMatrix (mtx_conv_obj->rows, mtx_conv_obj->columns, &mtx_conv_obj->x, &mtx_conv_obj->x_array); deleteTFloatMatrix (mtx_conv_obj->rows_y, mtx_conv_obj->columns_y, &mtx_conv_obj->y, &mtx_conv_obj->y_array); if (mtx_conv_obj->list) - freebytes (mtx_conv_obj->list, sizeof(t_float) * (mtx_conv_obj->size_y + 2)); + free (mtx_conv_obj->list); mtx_conv_obj->list = 0; } @@ -263,10 +262,9 @@ static void mTXConvMatrix (MTXConv *mtx_conv_obj, t_symbol *s, mtx_conv_obj->columns_y = columns_y; if (list_ptr) - list_ptr = (t_atom *) resizebytes (list_ptr, sizeof(t_atom) * (mtx_conv_obj->size_y+2), - sizeof (t_atom) * (size_y+2)); + list_ptr = (t_atom *) realloc (list_ptr, sizeof (t_atom) * (size_y+2)); else - list_ptr = (t_atom *) getbytes (sizeof (t_atom) * (size_y+2)); + list_ptr = (t_atom *) calloc (size_y+2, sizeof (t_atom)); mtx_conv_obj->list = list_ptr; if (!list_ptr) { post("mtx_conv: memory allocation failed!"); -- cgit v1.2.1