Double allocation of pixel data when using SDL_CreateRGBSurface with CreateDIBSection

Hi.

[OS] WinXP SP3
[SDL] 1.2.13

I have a memory leak when I’m combining SDL_CreateRGBSurface with CreateDIBSection functions.
Specifically I create a 32bit RGB surface and I’m passing it’s pixels pointer as a ‘hSection’ parameter od CreateDIBSection function.

I experimented on using some random void *data; to pass as a ‘hSection’ and then the memory gets released nicely.
So the problem is that SDL_CreateSurface and CreateDIBSection are both allocating memory at the same place but only one of it gets released.

I’m using this code to draw on win32 hwnd’s and I’ts based on Tom Wilson’s SDLToWin32 example found here http://www.polplex.co.uk/~tigger/sdl/
The code in question is in the SDLToWindows::createSurface function.

Is there anyway I can overide that double allocation?

Regards,
Dario

ELMA Kurtalj d.o.o. (ELMA Kurtalj ltd.)
Vitezi?eva 1a, 10000 Zagreb, Hrvatska (Viteziceva 1a, 10000 Zagreb, Croatia)
Tel: 01/3035555, Faks: 01/3035599 (Tel: ++385-1-3035555, Fax: ++385-1-3035599 )

Www:
www.elma.hr; shop.elma.hr

E-mail:
elma at elma.hr (elma at elma.hr)
pitanje at elma.hr (questions at elma.hr)
primjedbe at elma.hr (complaints at elma.hr)
prodaja at elma.hr (sales at elma.hr)
servis at elma.hr (servicing at elma.hr)
shop at elma.hr (shop at elma.hr)
skladiste at elma.hr (warehouse at elma.hr)

It doesn’t make sense that Windows (CreateDIBSection) would be responsible
for freeing the memory from an SDL_Surface. Windows has no way of knowing
how you allocated the memory for the pixels. Unless I’m misunderstanding
something, you created the SDL_Surface so it’s your responsibility to free
it.

Have you looked at the documentation for CreateDIBSection?
http://msdn.microsoft.com/en-us/library/dd183494(VS.85).aspx

According to that page it won’t allocate anything if you give it a non-NULL
hSection. It also says

If hSection is not NULL, it must be a handle to a file-mapping object

created by calling the CreateFileMappinghttp://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx function
with the PAGE_READWRITE or PAGE_WRITECOPY flag.

Perhaps the code you’re basing this off of is incorrect.On Thu, Apr 28, 2011 at 7:57 AM, Dario wrote:

Hi.

[OS] WinXP SP3
[SDL] 1.2.13

I have a memory leak when I’m combining SDL_CreateRGBSurface with
CreateDIBSection functions.
Specifically I create a 32bit RGB surface and I’m passing it’s pixels
pointer as a ‘hSection’ parameter od CreateDIBSection function.

I experimented on using some random void *data; to pass as a ‘hSection’ and
then the memory gets released nicely.
So the problem is that SDL_CreateSurface and CreateDIBSection are both
allocating memory at the same place but only one of it gets released.

I’m using this code to draw on win32 hwnd’s and I’ts based on Tom Wilson’s
SDLToWin32 example found here http://www.polplex.co.uk/~tigger/sdl/
The code in question is in the SDLToWindows::createSurface function.

Is there anyway I can overide that double allocation?

Regards,
Dario


ELMA Kurtalj d.o.o. (ELMA Kurtalj ltd.)

Vitezi?eva 1a, 10000 Zagreb, Hrvatska (Viteziceva 1a, 10000 Zagreb, Croatia)
Tel: 01/3035555, Faks: 01/3035599 (Tel: ++385-1-3035555, Fax:
++385-1-3035599 )

Www:
www.elma.hr; shop.elma.hr

E-mail:
elma at elma.hr (elma at elma.hr)
pitanje at elma.hr (questions at elma.hr)
primjedbe at elma.hr (complaints at elma.hr)
prodaja at elma.hr (sales at elma.hr)
servis at elma.hr (servicing at elma.hr)
shop at elma.hr (shop at elma.hr)
skladiste at elma.hr (warehouse at elma.hr)


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


Matthew Orlando
http://cogwheel.info