Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

freeing threadid on destroy, using safemalloc everywhere

  • Loading branch information...
commit 0c4b8bb2a5f00762d5df8c7ba16b7a954f098394 1 parent 2536d28
Tobias Leich authored
Showing with 10 additions and 9 deletions.
  1. +2 −2 src/SDLx/Controller/Interface.xs
  2. +7 −6 src/helper.h
  3. +1 −1  typemap
View
4 src/SDLx/Controller/Interface.xs
@@ -32,10 +32,10 @@ AV* acceleration_cb( SDLx_Interface * obj, float t )
SAVETMPS;
PUSHMARK(SP);
- void** pointers = malloc(3 * sizeof(void*));
+ void** pointers = safemalloc(3 * sizeof(void*));
pointers[0] = (void*)copyState;
pointers[1] = (void*)0;
- Uint32 *threadid = (Uint32 *)malloc(sizeof(Uint32));
+ Uint32 *threadid = (Uint32 *)safemalloc(sizeof(Uint32));
*threadid = SDL_ThreadID();
pointers[2] = (void*)threadid;
SV * state_obj = sv_setref_pv( stateref, "SDLx::Controller::State", (void *)pointers);
View
13 src/helper.h
@@ -23,10 +23,10 @@ void *bag2obj( SV *bag )
SV *obj2bag( int size_ptr, void *obj, char *CLASS )
{
SV * objref = newSV( size_ptr );
- void** pointers = malloc(3 * sizeof(void*));
+ void** pointers = safemalloc(3 * sizeof(void*));
pointers[0] = (void*)obj;
pointers[1] = (void*)PERL_GET_CONTEXT;
- Uint32 *threadid = (Uint32 *)malloc(sizeof(Uint32));
+ Uint32 *threadid = (Uint32 *)safemalloc(sizeof(Uint32));
*threadid = SDL_ThreadID();
pointers[2] = (void*)threadid;
sv_setref_pv( objref, CLASS, (void *)pointers);
@@ -39,10 +39,10 @@ SV *cpy2bag( void *object, int p_size, int s_size, char *package )
void *copy = safemalloc( s_size );
memcpy( copy, object, s_size );
- void** pointers = malloc(3 * sizeof(void*));
+ void** pointers = safemalloc(3 * sizeof(void*));
pointers[0] = (void*)copy;
pointers[1] = (void*)PERL_GET_CONTEXT;
- Uint32 *threadid = (Uint32 *)malloc(sizeof(Uint32));
+ Uint32 *threadid = (Uint32 *)safemalloc(sizeof(Uint32));
*threadid = SDL_ThreadID();
pointers[2] = (void*)threadid;
SV* a = newSVsv(sv_setref_pv(ref, package, (void *)pointers));
@@ -64,6 +64,7 @@ void objDESTROY(SV *bag, void (* callback)(void *object))
pointers[0] = NULL;
if(object)
callback(object);
+ safefree(threadid);
safefree(pointers);
}
}
@@ -75,10 +76,10 @@ SV *_sv_ref( void *object, int p_size, int s_size, char *package )
void *copy = safemalloc( s_size );
memcpy( copy, object, s_size );
- void** pointers = malloc(3 * sizeof(void*));
+ void** pointers = safemalloc(3 * sizeof(void*));
pointers[0] = (void*)copy;
pointers[1] = (void*)perl;
- Uint32 *threadid = (Uint32 *)malloc(sizeof(Uint32));
+ Uint32 *threadid = (Uint32 *)safemalloc(sizeof(Uint32));
*threadid = SDL_ThreadID();
pointers[2] = (void*)threadid;
View
2  typemap
@@ -114,7 +114,7 @@ O_OBJECT
void** pointers = malloc(3 * sizeof(void*));
pointers[0] = (void*)$var;
pointers[1] = (void*)PERL_GET_CONTEXT;
- Uint32 *threadid = (Uint32 *)malloc(sizeof(Uint32));
+ Uint32 *threadid = (Uint32 *)safemalloc(sizeof(Uint32));
*threadid = SDL_ThreadID();
pointers[2] = (void*)threadid;
sv_setref_pv( $arg, CLASS, (void*)pointers );
Please sign in to comment.
Something went wrong with that request. Please try again.