[SDL] SDL2 error on iOS (doublefree)

Tim Angus tim at ngus.net
Tue Feb 7 10:37:25 PST 2012

On 07/02/2012 14:47, Tim Angus wrote:
> As I said before though the real fix is probably as follows:
>>> P.S. It could be argued that the real bug is that UIKit_AddDisplay
>>> should
>>> create new copies of mode when assigning to display.desktop_mode and
>>> display.current_mode and thus avoid the icky double retain on mode. I'll
>>> probably have a look at this when I get a chance...

OK, I had a little chance to have a peek at this. Having had a closer 
look at things, I believe the actual problem is that current_mode should 
not be retained or owned at all. If you look at the rest of SDL it's 
used as a reference to other modes rather than a mode in its own right. 
It would probably help get its semantics clear if its type was actually 
a pointer rather than a value i.e.:

  struct SDL_VideoDisplay
      int max_display_modes;
      int num_display_modes;
      SDL_DisplayMode *display_modes;
      SDL_DisplayMode desktop_mode;
-    SDL_DisplayMode current_mode;
+    SDL_DisplayMode *current_mode;

      SDL_Window *fullscreen_window;

      SDL_VideoDevice *device;

      void *driverdata;

The attached patch contains a bit of extra noise to centralise the 
allocation of SDL_DisplayModeData, but in essence the fix is just to not 
retain, allocate or free current_mode, and treat it as a weak reference 
only. I haven't really had time to properly test this so YMMV, but I 
think this is the correct route to take.

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: sdl2-ios-double-free-fix.diff
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20120207/c4cf9033/attachment-0008.txt>

More information about the SDL mailing list