Permalink
Browse files

Fixed leaking of references

  • Loading branch information...
1 parent 8fb1bfc commit fb19ae52d37f54afbd0752fa842efe4e4ca57a32 @kthakore kthakore committed Dec 23, 2010
Showing with 37 additions and 12 deletions.
  1. +24 −6 src/SDLx/Surface.xs
  2. +2 −2 src/SDLx/Validate.h
  3. +10 −3 src/helper.h
  4. +1 −1 typemap
View
@@ -186,14 +186,18 @@ surfacex_draw_rect ( surface, rt, color )
if( SvOK(rt) )
{
int newly_created_rect = 0;
- SDL_Rect* v_rect = (SDL_Rect*)bag2obj(rect( rt, &newly_created_rect ));
+ SV* foo = rect( rt, &newly_created_rect );
+ SDL_Rect* v_rect = (SDL_Rect*)bag2obj(foo);
r_rect.x = v_rect->x;
r_rect.y = v_rect->y;
r_rect.w = v_rect->w;
r_rect.h = v_rect->h;
-/* if( newly_created_rect == 1 ) { safefree( v_rect); } */
+ SDL_FillRect(surface, &r_rect, m_color);
+ SvREFCNT_dec(foo);
+ //if( newly_created_rect == 1 ) { safefree( v_rect); }
}
- SDL_FillRect(surface, &r_rect, m_color);
+ else
+ SDL_FillRect(surface, &r_rect, m_color);
void
surfacex_blit( src, dest, ... )
@@ -208,9 +212,14 @@ surfacex_blit( src, dest, ... )
SDL_Rect _src_rect;
SDL_Rect _dest_rect;
int newly_created_rect = 0;
-
+ SV* s_rect_sv, *d_rect_sv;
+ int mall_sr = 0; int mall_dr = 0;
if( items > 2 && SvOK(ST(2)) )
- _src_rect = *(SDL_Rect *)bag2obj( rect(ST(2), &newly_created_rect) );
+ {
+ s_rect_sv = rect(ST(2), &newly_created_rect);
+ _src_rect = *(SDL_Rect *)bag2obj( s_rect_sv );
+ mall_sr = 1;
+ }
else
{
_src_rect.x = 0;
@@ -220,7 +229,11 @@ surfacex_blit( src, dest, ... )
}
if( items > 3 && SvOK(ST(3)) )
- _dest_rect = *(SDL_Rect *)bag2obj( rect(ST(3), &newly_created_rect) );
+ {
+ d_rect_sv = rect(ST(3), &newly_created_rect);
+ _dest_rect = *(SDL_Rect *)bag2obj( d_rect_sv );
+ mall_dr = 1;
+ }
else
{
_dest_rect.x = 0;
@@ -230,4 +243,9 @@ surfacex_blit( src, dest, ... )
}
SDL_BlitSurface( _src, &_src_rect, _dest, &_dest_rect );
+ if ( mall_sr == 1 )
+ SvREFCNT_dec( s_rect_sv);
+ if ( mall_dr == 1 )
+ SvREFCNT_dec( d_rect_sv );
+
View
@@ -10,7 +10,7 @@ SV *rect( SV *rect, int* new_rect_made)
if( !SvOK(rect) )
{
SDL_Rect* r = safemalloc( sizeof(SDL_Rect) );
- (*new_rect_made) = 1;
+ (*new_rect_made) = 1;
r->x = 0;
r->y = 0;
r->w = 0;
@@ -20,7 +20,7 @@ SV *rect( SV *rect, int* new_rect_made)
else if( sv_derived_from(rect, "ARRAY") )
{
SDL_Rect* r = safemalloc( sizeof(SDL_Rect) );
- (*new_rect_made) = 1;
+ (*new_rect_made) = 1;
int ra[4];
int i = 0;
AV* recta = (AV*)SvRV(rect);
View
@@ -23,7 +23,6 @@ SV *obj2bag( int size_ptr, void *obj, char *CLASS )
pointers[0] = (void*)obj;
pointers[1] = (void*)PERL_GET_CONTEXT;
sv_setref_pv( objref, CLASS, (void *)pointers);
-
return objref;
}
@@ -37,7 +36,8 @@ SV *cpy2bag( void *object, int p_size, int s_size, char *package )
pointers[0] = (void*)copy;
pointers[1] = (void*)PERL_GET_CONTEXT;
- return newSVsv(sv_setref_pv(ref, package, (void *)pointers));
+ SV* a = newSVsv(sv_setref_pv(ref, package, (void *)pointers));
+ return a;
}
void objDESTROY(SV *bag, void (* callback)(void *object))
@@ -48,7 +48,7 @@ void objDESTROY(SV *bag, void (* callback)(void *object))
void* object = pointers[0];
if (PERL_GET_CONTEXT == pointers[1])
{
- pointers[0] = NULL;
+ pointers[0] = NULL;
if(object)
callback(object);
safefree(pointers);
@@ -69,4 +69,11 @@ SV *_sv_ref( void *object, int p_size, int s_size, char *package )
return newSVsv(sv_setref_pv(ref, package, (void *)pointers));
}
+void print_pointer( const char* message, void* pointer )
+{
+
+ warn( "%s %p", message, pointer);
+
+}
+
#endif
View
@@ -114,7 +114,7 @@ O_OBJECT
void** pointers = malloc(2 * sizeof(void*));
pointers[0] = (void*)$var;
pointers[1] = (void*)PERL_GET_CONTEXT;
- sv_setref_pv( $arg, CLASS, (void*)pointers );
+ sv_setref_pv( $arg, CLASS, (void*)pointers );
} else {
XSRETURN_UNDEF;
}

0 comments on commit fb19ae5

Please sign in to comment.