From baaf1384823f750adf900ffde67094fb5cda71b2 Mon Sep 17 00:00:00 2001
From: Lars Kanis <kanis@comcard.de>
Date: Sat, 16 Jun 2012 22:37:35 +0200
Subject: [PATCH] Fix Segfault in final GC when using FXSplashWindow.

The internal object allocated when calling FXSplashWindow.new was FXSplashWindow instead
of FXRbSplashWindow, so that no FXRbUnregisterRubyObj() was called. Therefore the object
was double free'd.

Stacktrace was:
==11529== Invalid read of size 8
==11529==    at 0x9265BBC: FX::FXObject::getClassName() const (FXObject.cpp:280)
==11529==    by 0x862EE55: FXRbObject::freefunc(FX::FXObject*) (markfuncs.cpp:77)
==11529==    by 0x4EA6254: finalize_list (gc.c:2944)
==11529==    by 0x4EAAFC2: rb_gc_call_finalizer_at_exit (gc.c:3075)
==11529==    by 0x4E9773B: ruby_cleanup (eval.c:101)
==11529==    by 0x4E979C4: ruby_run_node (eval.c:244)
==11529==    by 0x4007FA: main (main.c:38)
==11529==  Address 0x75e24c0 is 0 bytes inside a block of size 248 free'd
==11529==    at 0x4C2A4BC: operator delete(void*) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11529==    by 0x92B98AD: FX::FXSplashWindow::~FXSplashWindow() (FXSplashWindow.cpp:219)
==11529==    by 0x917C990: FX::FXComposite::~FXComposite() (FXComposite.cpp:304)
==11529==    by 0x929A5EF: FX::FXRootWindow::~FXRootWindow() (FXRootWindow.cpp:209)
==11529==    by 0x929A621: FX::FXRootWindow::~FXRootWindow() (FXRootWindow.cpp:211)
==11529==    by 0x9156DB9: FX::FXApp::~FXApp() (FXApp.cpp:4994)
==11529==    by 0x84912F3: FXRbApp::~FXRbApp() (FXRbApp.cpp:118)
==11529==    by 0x8491347: FXRbApp::~FXRbApp() (FXRbApp.cpp:127)
==11529==    by 0x862EF8E: FXRbObject::freefunc(FX::FXObject*) (markfuncs.cpp:92)
==11529==    by 0x4EA6254: finalize_list (gc.c:2944)
==11529==    by 0x4EAAFC2: rb_gc_call_finalizer_at_exit (gc.c:3075)
==11529==    by 0x4E9773B: ruby_cleanup (eval.c:101)
---
 ext/fox16/MANIFEST               |  1 +
 ext/fox16/include/impl.h         |  1 +
 swig-interfaces/FXSplashWindow.i | 14 ++++++++++----
 3 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/ext/fox16/MANIFEST b/ext/fox16/MANIFEST
index 4eb4f60..fd5ea8e 100755
--- a/ext/fox16/MANIFEST
+++ b/ext/fox16/MANIFEST
@@ -148,6 +148,7 @@ include/FXRbShutter.h
 include/FXRbShutterVirtuals.h
 include/FXRbSlider.h
 include/FXRbSpinner.h
+include/FXRbSplashWindow.h
 include/FXRbSplitter.h
 include/FXRbStatusbar.h
 include/FXRbStatusline.h
diff --git a/ext/fox16/include/impl.h b/ext/fox16/include/impl.h
index 5e9f28b..822b164 100644
--- a/ext/fox16/include/impl.h
+++ b/ext/fox16/include/impl.h
@@ -166,6 +166,7 @@ FXRbIMPLEMENT(FXRbShutter,FXShutter,NULL,0)
 FXRbIMPLEMENT(FXRbShutterItem,FXShutterItem,NULL,0)
 FXRbIMPLEMENT(FXRbSlider,FXSlider,NULL,0)
 FXRbIMPLEMENT(FXRbSpinner,FXSpinner,NULL,0)
+FXRbIMPLEMENT(FXRbSplashWindow,FXSplashWindow,NULL,0)
 FXRbIMPLEMENT(FXRbSplitter,FXSplitter,NULL,0)
 FXRbIMPLEMENT(FXRbSpring,FXSpring,NULL,0)
 FXRbIMPLEMENT(FXRbStatusBar,FXStatusBar,NULL,0)
diff --git a/swig-interfaces/FXSplashWindow.i b/swig-interfaces/FXSplashWindow.i
index 02c59cf..bd0937f 100644
--- a/swig-interfaces/FXSplashWindow.i
+++ b/swig-interfaces/FXSplashWindow.i
@@ -52,11 +52,17 @@ public:
   long onPaint(FXObject*,FXSelector,void* PTR_EVENT);
 public:
 
-  /// Construct splash window
-  FXSplashWindow(FXApp* a,FXIcon* ic,FXuint opts=SPLASH_SIMPLE,FXuint ms=5000);
+  %extend {
+    /// Construct splash window
+    FXSplashWindow(FXApp* a,FXIcon* ic,FXuint opts=SPLASH_SIMPLE,FXuint ms=5000){
+      return new FXRbSplashWindow(a,ic,opts,ms);
+      }
 
-  /// Construct splash window
-  FXSplashWindow(FXWindow* own,FXIcon* ic,FXuint opts=SPLASH_SIMPLE,FXuint ms=5000);
+    /// Construct splash window
+    FXSplashWindow(FXWindow* own,FXIcon* ic,FXuint opts=SPLASH_SIMPLE,FXuint ms=5000){
+      return new FXRbSplashWindow(own,ic,opts,ms);
+      }
+    }
 
   /// Set the icon for the splash window
   void setIcon(FXIcon* ic);
-- 
GitLab