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 2299

Summary: Memory leak in SDL_CreateYUV_SW
Product: SDL Reporter: Nitz <nitin.j4>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: critical    
Priority: P2 CC: arvin.mittal, philipp.wiesemann
Version: 1.2.15   
Hardware: x86   
OS: Linux   
Attachments: Patch

Description Nitz 2013-12-12 05:48:15 UTC
In SDL_Overlay *SDL_CreateYUV_SW(_THIS, int width, int height, Uint32 format, SDL_Surface *display)

function, 3 pointers are getting leak:
1. swdata->pixels
2. swdata->colortab
3. swdata->rgb_2_pix
 
at this point:
if ( ! swdata->pixels || ! swdata->colortab || ! swdata->rgb_2_pix ) {
                SDL_OutOfMemory();
                SDL_FreeYUVOverlay(overlay);
                return(NULL);
        }
Patch:

swdata->pixels = (Uint8 *) SDL_malloc(width*height*2);
if(! swdata->pixels)
{
  SDL_OutOfMemory();
  SDL_FreeYUVOverlay(overlay);
  return(NULL);
}
swdata->colortab = (int *)SDL_malloc(4*256*sizeof(int));
if(! swdata->colortab )
{
  SDL_free(swdata->pixels);
  SDL_OutOfMemory();
  SDL_FreeYUVOverlay(overlay);
  return(NULL);
}
swdata->rgb_2_pix = (Uint32 *)SDL_malloc(3*768*sizeof(Uint32));
if(! swdata->rgb_2_pix)
{
  SDL_free(swdata->pixels);
  SDL_free(swdata->colortab);
  SDL_OutOfMemory();
  SDL_FreeYUVOverlay(overlay);
  return(NULL);
}

        Cr_r_tab = &swdata->colortab[0*256];
        Cr_g_tab = &swdata->colortab[1*256];
        Cb_g_tab = &swdata->colortab[2*256];
        Cb_b_tab = &swdata->colortab[3*256];
        
        r_2_pix_alloc = &swdata->rgb_2_pix[0*768];
        g_2_pix_alloc = &swdata->rgb_2_pix[1*768];
        b_2_pix_alloc = &swdata->rgb_2_pix[2*768];
        

Thanks
Comment 1 Philipp Wiesemann 2014-10-29 20:09:53 UTC
Seems a duplicate of bug 2334 but the patch is different there.
Comment 2 Nitz 2014-10-30 03:35:19 UTC
Created attachment 1920 [details]
Patch

This patch is tested and having no issue.
Comment 3 Nitz 2014-10-30 03:37:13 UTC
Yes Mr.Philipp that seems to be an duplicate issue reported by someone else.
I attached the final path which has been tested having no issue.
So it is safe to apply.

Thanks!!!
Comment 4 Philipp Wiesemann 2014-11-01 12:27:41 UTC
From looking at the source of SDL_yuv_sw.c it seems to me that all three pointers would also be deleted with SDL_FreeYUVOverlay() because it indirectly calls SDL_FreeYUV_SW(). If this is the case there would be no leak.
Comment 5 Philipp Wiesemann 2014-11-01 12:44:20 UTC
*** Bug 2334 has been marked as a duplicate of this bug. ***
Comment 6 Nitz 2014-11-03 03:18:00 UTC
Ohh yee you are right....
thanks for your inputs :)
Comment 7 Philipp Wiesemann 2014-12-03 20:28:02 UTC
Resolved as invalid because there seems to be no leak. See previous discussion.