Skip to content

Commit

Permalink
Removed unecessary temp var, documented issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Apr 26, 2017
1 parent 8aadc7e commit f95a3fd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
16 changes: 9 additions & 7 deletions library/rpi_ws281x.i
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ static int convert_iarray(PyObject *input, uint8_t *ptr, int size) {
}
%}

%typemap(in) uint8_t * (uint8_t temp[256]) {
if (!convert_iarray($input,temp,256)) {
return NULL;
}
%typemap(in) uint8_t * {
/* As a consequence of this malloc, I believe there's a potential memory leak
/ which would occur if gamma is set more than once.
/ The gamma value is only freed once at cleanup.
/ Using a typemap is also risky here, since it would apply to all *uint8_t,
/ this type is presently only used for the gamma table.
*/
$1 = malloc(sizeof(uint8_t) * 256);
int n;
for(n = 0; n < 256; n++){
$1[n] = temp[n];
if (!convert_iarray($input,$1,256)) {
return NULL;
}
}

Expand Down
15 changes: 8 additions & 7 deletions library/rpi_ws281x_wrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3856,7 +3856,6 @@ SWIGINTERN PyObject *_wrap_ws2811_channel_t_gamma_set(PyObject *SWIGUNUSEDPARM(s
uint8_t *arg2 = (uint8_t *) 0 ;
void *argp1 = 0 ;
int res1 = 0 ;
uint8_t temp2[256] ;
PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;

Expand All @@ -3867,13 +3866,15 @@ SWIGINTERN PyObject *_wrap_ws2811_channel_t_gamma_set(PyObject *SWIGUNUSEDPARM(s
}
arg1 = (ws2811_channel_t *)(argp1);
{
if (!convert_iarray(obj1,temp2,256)) {
return NULL;
}
/* As a consequence of this malloc, I believe there's a potential memory leak
/ which would occur if gamma is set more than once.
/ The gamma value is only freed once at cleanup.
/ Using a typemap is also risky here, since it would apply to all *uint8_t,
/ this type is presently only used for the gamma table.
*/
arg2 = malloc(sizeof(uint8_t) * 256);
int n;
for(n = 0; n < 256; n++){
arg2[n] = temp2[n];
if (!convert_iarray(obj1,arg2,256)) {
return NULL;
}
}
if (arg1) (arg1)->gamma = arg2;
Expand Down

0 comments on commit f95a3fd

Please sign in to comment.