]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/utilsgtk.cpp
free old resources in DoLoad(), apparently fixes memory leaks with gstreamer 0.10...
[wxWidgets.git] / src / gtk / utilsgtk.cpp
index ed16a667e05a5a39051ff00c95785c42720b43eb..1144d39c3aacb86f41a2bc4a424f8dadcec051b9 100644 (file)
@@ -293,41 +293,52 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
 #if wxUSE_DETECT_SM
 static wxString GetSM()
 {
-       Display     *dpy;
-       SmcConn     smc_conn;
-       char        *vendor;
-       char        *client_id_ret;
-       dpy = XOpenDisplay(NULL);
-
-       smc_conn = SmcOpenConnection(NULL, NULL,
-                                    999, 999,
-                                    0 /* mask */, NULL /* callbacks */,
-                                    NULL, &client_id_ret, 0, NULL);
-
-       vendor = SmcVendor(smc_conn);
+    class Dpy
+    {
+    public:
+        Dpy() { m_dpy = XOpenDisplay(NULL); }
+        ~Dpy() { if ( m_dpy ) XCloseDisplay(m_dpy); }
+
+        operator Display *() const { return m_dpy; }
+    private:
+        Display *m_dpy;
+    } dpy;
+
+    if ( !dpy )
+        return wxEmptyString;
+
+    char *client_id;
+    SmcConn smc_conn = SmcOpenConnection(NULL, NULL,
+                                         999, 999,
+                                         0 /* mask */, NULL /* callbacks */,
+                                         NULL, &client_id,
+                                         0, NULL);
+
+    if ( !smc_conn )
+        return wxEmptyString;
+
+    char *vendor = SmcVendor(smc_conn);
     wxString ret = wxString::FromAscii( vendor );
-       free(vendor);
+    free(vendor);
 
-       SmcCloseConnection(smc_conn, 0, NULL);
-       free(client_id_ret);
+    SmcCloseConnection(smc_conn, 0, NULL);
+    free(client_id);
 
-       XCloseDisplay(dpy);
-    
     return ret;
 }
-#endif
+#endif // wxUSE_DETECT_SM
 
 wxString wxGUIAppTraits::GetDesktopEnvironment() const
 {
 #if wxUSE_DETECT_SM
-    wxString SM = GetSM();
-    
+    const wxString SM = GetSM();
+
     if (SM == wxT("GnomeSM"))
         return wxT("GNOME");
-        
+
     if (SM == wxT("KDE"))
         return wxT("KDE");
-#endif
+#endif // wxUSE_DETECT_SM
 
     return wxEmptyString;
 }