We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2015 - surface getting leak in SDLTest_ScreenShot function
Summary: surface getting leak in SDLTest_ScreenShot function
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 2.0.0
Hardware: x86 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-06 03:53 UTC by Nitz
Modified: 2013-10-21 07:30 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nitz 2013-08-06 03:53:41 UTC
In function:
static void
SDLTest_ScreenShot(SDL_Renderer *renderer)
{
        //Some Code
        surface = SDL_CreateRGBSurface(0, viewport.w, viewport.h, 24,
        #if SDL_BYTEORDER == SDL_LIL_ENDIAN
                    0x00FF0000, 0x0000FF00, 0x000000FF,
        #else
                    0x000000FF, 0x0000FF00, 0x00FF0000,
       #endif
                    0x00000000);
    if (!surface) {
        fprintf(stderr, "Couldn't create surface: %s\n", SDL_GetError());
        return;
    }

    if (SDL_RenderReadPixels(renderer, NULL, surface->format->format,
                             surface->pixels, surface->pitch) < 0) {
        fprintf(stderr, "Couldn't read screen: %s\n", SDL_GetError());
        return;
    }

    if (SDL_SaveBMP(surface, "screenshot.bmp") < 0) {
        fprintf(stderr, "Couldn't save screenshot.bmp: %s\n", SDL_GetError());
        return;
    }
}

surface pointer getting leak while return so fix should be

    if (SDL_RenderReadPixels(renderer, NULL, surface->format->format,
                             surface->pixels, surface->pitch) < 0) {
        fprintf(stderr, "Couldn't read screen: %s\n", SDL_GetError());

        SDL_free(surface);

        return;
    }

    if (SDL_SaveBMP(surface, "screenshot.bmp") < 0) {
        fprintf(stderr, "Couldn't save screenshot.bmp: %s\n", SDL_GetError());

        SDL_free(surface);

        return;
    }

Thanks!
Comment 1 Sam Lantinga 2013-10-21 07:30:26 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL/rev/6871ab38d224