SDL_FreeSurface() confusion

Hello all,
I’m having difficulty with SDL_FreeSurface(). In a function, I
initalize a surface like:

SDL_Surface *image;

I later then say,

image = (SDL_Surface *)ship->hull->image;

(where the ship structure contains another structure, hull, which
defines image as SDL_Surface *image)

I then create two SDL_Rects, set the x,y,w,h values, use
SDL_BlitSurface() to blit image, however, because this function is
called often, I don’t want to create a memory leak, so I should free up
image, right?

SDL_FreeSurface(image);

and it crashes right there w/ an SDL Parachute. Perhaps I’m getting
something with pointers mixed up? Anybody know what’s wrong and/or
should I provide more code?–
Chris
@Christopher_Thielen

I’m having difficulty with SDL_FreeSurface(). In a function, I
initalize a surface like:

SDL_Surface *image;

This doesn’t initialise a surface. It just creates a pointer that can
later point to a surface.

I then create two SDL_Rects, set the x,y,w,h values, use
SDL_BlitSurface() to blit image, however, because this function is
called often, I don’t want to create a memory leak, so I should free
up
image, right?

Wrong. You’ve not created an extra image, you just pointed to an
existing one. So you shouldn’t free it, as you’ve got exactly the same
number of images as before.From: chris@luethy.net (Christopher Thielen)
Sent: Tuesday, May 21, 2002 12:41 AM


Kylotan