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 1950

Summary: Sometimes SDL_calloc returns NULL in SDL_CreateWindowFrom(const void *data) function
Product: SDL Reporter: Nitz <nitin.j4>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: major    
Priority: P2    
Version: 2.0.0   
Hardware: x86   
OS: Linux   

Description Nitz 2013-07-10 04:11:53 UTC
In Function:
SDL_Window *
SDL_CreateWindowFrom(const void *data)
{
    SDL_Window *window;

    if (!_this) {
        SDL_UninitializedVideo();
        return NULL;
    }
    window = (SDL_Window *)SDL_calloc(1, sizeof(*window));// In this SDL_calloc sometimes may return NULL. 

   //Some code
}

In above function SDL_calloc sometimes may return NULL to windows, which is not accepted.
So to avoid this, patch should be:

window = (SDL_Window *)SDL_calloc(1, sizeof(SDL_Window));

Thanks,
Nitz
Comment 1 Sam Lantinga 2013-07-11 01:14:28 UTC
The sizeof() is fine, but you're right that it needs to check the return value of SDL_calloc().

This is now fixed, thanks!
http://hg.libsdl.org/SDL/rev/f35ff854121a