GHOST cleanup (null check before delete, and 0 -> NULL for pointers).
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 24 May 2016 09:47:48 +0000 (11:47 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 24 May 2016 09:49:30 +0000 (11:49 +0200)
Based on patch from Lawrence D'Oliveiro (ldo) in T48499.

12 files changed:
intern/ghost/intern/GHOST_ContextSDL.cpp
intern/ghost/intern/GHOST_DropTargetWin32.cpp
intern/ghost/intern/GHOST_ISystem.cpp
intern/ghost/intern/GHOST_ISystemPaths.cpp
intern/ghost/intern/GHOST_System.cpp
intern/ghost/intern/GHOST_SystemCocoa.mm
intern/ghost/intern/GHOST_SystemWin32.cpp
intern/ghost/intern/GHOST_SystemX11.cpp
intern/ghost/intern/GHOST_Window.h
intern/ghost/intern/GHOST_WindowCocoa.mm
intern/ghost/intern/GHOST_WindowManager.cpp
intern/ghost/intern/GHOST_WindowWin32.cpp

index d80a638..39627fa 100644 (file)
@@ -69,7 +69,7 @@ GHOST_ContextSDL::GHOST_ContextSDL(
 GHOST_ContextSDL::~GHOST_ContextSDL()
 {
        if (m_context != NULL) {
-               if (m_window != 0 && m_context == SDL_GL_GetCurrentContext())
+               if (m_window != NULL && m_context == SDL_GL_GetCurrentContext())
                        SDL_GL_MakeCurrent(m_window, m_context);
 
                if (m_context != s_sharedContext || s_sharedCount == 1) {
index fd9abce..96ff79a 100644 (file)
@@ -75,7 +75,7 @@ HRESULT __stdcall GHOST_DropTargetWin32::QueryInterface(REFIID riid, void **ppvO
                return S_OK;
        }
        else {
-               *ppvObj = 0;
+               *ppvObj = NULL;
                return E_NOINTERFACE;
        }
 }
@@ -97,8 +97,7 @@ ULONG __stdcall GHOST_DropTargetWin32::Release(void)
 {
        ULONG refs = ::InterlockedDecrement(&m_cRef);
                
-       if (refs == 0)
-       {
+       if (refs == 0) {
                delete this;
                return 0;
        }
index d7dd2b1..37d5926 100644 (file)
@@ -54,7 +54,7 @@
 #  endif
 #endif
 
-GHOST_ISystem *GHOST_ISystem::m_system = 0;
+GHOST_ISystem *GHOST_ISystem::m_system = NULL;
 
 
 GHOST_TSuccess GHOST_ISystem::createSystem()
@@ -76,7 +76,7 @@ GHOST_TSuccess GHOST_ISystem::createSystem()
 #    endif
 #  endif
 #endif
-               success = m_system != 0 ? GHOST_kSuccess : GHOST_kFailure;
+               success = m_system != NULL ? GHOST_kSuccess : GHOST_kFailure;
        }
        else {
                success = GHOST_kFailure;
@@ -92,7 +92,7 @@ GHOST_TSuccess GHOST_ISystem::disposeSystem()
        GHOST_TSuccess success = GHOST_kSuccess;
        if (m_system) {
                delete m_system;
-               m_system = 0;
+               m_system = NULL;
        }
        else {
                success = GHOST_kFailure;
index 6ebcb37..93ca0bc 100644 (file)
@@ -36,6 +36,9 @@
  * \date       May 7, 2001
  */
 
+
+#include <stdio.h> /* just for NULL */
+
 #include "GHOST_ISystemPaths.h"
 
 #ifdef WIN32
@@ -49,7 +52,7 @@
 #endif
 
 
-GHOST_ISystemPaths *GHOST_ISystemPaths::m_systemPaths = 0;
+GHOST_ISystemPaths *GHOST_ISystemPaths::m_systemPaths = NULL;
 
 
 GHOST_TSuccess GHOST_ISystemPaths::create()
@@ -65,7 +68,7 @@ GHOST_TSuccess GHOST_ISystemPaths::create()
                m_systemPaths = new GHOST_SystemPathsUnix();
 #  endif
 #endif 
-               success = m_systemPaths != 0 ? GHOST_kSuccess : GHOST_kFailure;
+               success = m_systemPaths != NULL ? GHOST_kSuccess : GHOST_kFailure;
        }
        else {
                success = GHOST_kFailure;
@@ -78,7 +81,7 @@ GHOST_TSuccess GHOST_ISystemPaths::dispose()
        GHOST_TSuccess success = GHOST_kSuccess;
        if (m_systemPaths) {
                delete m_systemPaths;
-               m_systemPaths = 0;
+               m_systemPaths = NULL;
        }
        else {
                success = GHOST_kFailure;
index 0f5c822..639ce45 100644 (file)
@@ -88,7 +88,7 @@ GHOST_ITimerTask *GHOST_System::installTimer(GHOST_TUns64 delay,
                }
                else {
                        delete timer;
-                       timer = 0;
+                       timer = NULL;
                }
        }
        return timer;
@@ -328,27 +328,22 @@ GHOST_TSuccess GHOST_System::exit()
        if (getFullScreen()) {
                endFullScreen();
        }
-       if (m_displayManager) {
-               delete m_displayManager;
-               m_displayManager = NULL;
-       }
-       if (m_windowManager) {
-               delete m_windowManager;
-               m_windowManager = NULL;
-       }
-       if (m_timerManager) {
-               delete m_timerManager;
-               m_timerManager = NULL;
-       }
-       if (m_eventManager) {
-               delete m_eventManager;
-               m_eventManager = NULL;
-       }
+
+       delete m_displayManager;
+       m_displayManager = NULL;
+
+       delete m_windowManager;
+       m_windowManager = NULL;
+
+       delete m_timerManager;
+       m_timerManager = NULL;
+
+       delete m_eventManager;
+       m_eventManager = NULL;
+
 #ifdef WITH_INPUT_NDOF
-       if (m_ndofManager) {
-               delete m_ndofManager;
-               m_ndofManager = 0;
-       }
+       delete m_ndofManager;
+       m_ndofManager = NULL;
 #endif
        return GHOST_kSuccess;
 }
index bf44d93..c9855cf 100644 (file)
@@ -539,7 +539,7 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
 )
 {
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
-       GHOST_IWindow* window = 0;
+       GHOST_IWindow* window = NULL;
        
        //Get the available rect for including window contents
        NSRect frame = [[NSScreen mainScreen] visibleFrame];
@@ -567,7 +567,7 @@ GHOST_IWindow* GHOST_SystemCocoa::createWindow(
        else {
                GHOST_PRINT("GHOST_SystemCocoa::createWindow(): window invalid\n");
                delete window;
-               window = 0;
+               window = NULL;
        }
        
        [pool drain];
index d8ec827..43fb5dc 100644 (file)
@@ -253,7 +253,7 @@ GHOST_IWindow *GHOST_SystemWin32::createWindow(
        else {
                GHOST_PRINT("GHOST_SystemWin32::createWindow(): window invalid\n");
                delete window;
-               window = 0;
+               window = NULL;
        }
 
        return window;
@@ -766,7 +766,7 @@ GHOST_EventKey *GHOST_SystemWin32::processKeyEvent(GHOST_WindowWin32 *window, RA
                // GHOST_PRINTF("%c\n", ascii); // we already get this info via EventPrinter
        }
        else {
-               event = 0;
+               event = NULL;
        }
        return event;
 }
@@ -900,7 +900,7 @@ bool GHOST_SystemWin32::processNDOF(RAWINPUT const &raw)
 
 LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
-       GHOST_Event *event = 0;
+       GHOST_Event *event = NULL;
        bool eventHandled = false;
 
        LRESULT lResult = 0;
index 95dea38..c9946c1 100644 (file)
@@ -302,7 +302,7 @@ createWindow(const STR_String& title,
                const bool exclusive,
                const GHOST_TEmbedderWindowID parentWindow)
 {
-       GHOST_WindowX11 *window = 0;
+       GHOST_WindowX11 *window = NULL;
        
        if (!m_display) return 0;
        
@@ -324,7 +324,7 @@ createWindow(const STR_String& title,
                }
                else {
                        delete window;
-                       window = 0;
+                       window = NULL;
                }
        }
        return window;
index 52cb9cb..d778628 100644 (file)
@@ -106,7 +106,7 @@ public:
         * \return The validity of the window.
         */
        virtual bool getValid() const { 
-               return m_context != 0;
+               return m_context != NULL;
        }
 
        /**
index b3fc8ef..00e00b6 100644 (file)
@@ -663,7 +663,7 @@ GHOST_WindowCocoa::~GHOST_WindowCocoa()
 
 bool GHOST_WindowCocoa::getValid() const
 {
-       return GHOST_Window::getValid() && m_window != 0 && m_openGLView != 0;
+       return GHOST_Window::getValid() && m_window != NULL && m_openGLView != NULL;
 }
 
 void* GHOST_WindowCocoa::getOSWindow() const
index 83490ce..790c73d 100644 (file)
@@ -110,7 +110,7 @@ bool GHOST_WindowManager::getWindowFound(const GHOST_IWindow *window) const
 
 bool GHOST_WindowManager::getFullScreen(void) const
 {
-       return m_fullScreenWindow != 0;
+       return m_fullScreenWindow != NULL;
 }
 
 
@@ -140,13 +140,13 @@ GHOST_TSuccess GHOST_WindowManager::endFullScreen(void)
 {
        GHOST_TSuccess success = GHOST_kFailure;
        if (getFullScreen()) {
-               if (m_fullScreenWindow != 0) {
+               if (m_fullScreenWindow != NULL) {
                        //GHOST_PRINT("GHOST_WindowManager::endFullScreen(): deleting full-screen window\n");
                        setWindowInactive(m_fullScreenWindow);
                        m_fullScreenWindow->endFullScreen();
                        delete m_fullScreenWindow;
                        //GHOST_PRINT("GHOST_WindowManager::endFullScreen(): done\n");
-                       m_fullScreenWindow = 0;
+                       m_fullScreenWindow = NULL;
                        if (m_activeWindowBeforeFullScreen) {
                                setActiveWindow(m_activeWindowBeforeFullScreen);
                        }
@@ -181,7 +181,7 @@ GHOST_IWindow *GHOST_WindowManager::getActiveWindow(void) const
 void GHOST_WindowManager::setWindowInactive(const GHOST_IWindow *window)
 {
        if (window == m_activeWindow) {
-               m_activeWindow = 0;
+               m_activeWindow = NULL;
        }
 }
 
index 7247753..81c08f4 100644 (file)
@@ -339,8 +339,7 @@ GHOST_WindowWin32::~GHOST_WindowWin32()
                if (fpWTClose) {
                        if (m_tablet)
                                fpWTClose(m_tablet);
-                       if (m_tabletData)
-                               delete m_tabletData;
+                       delete m_tabletData;
                        m_tabletData = NULL;
                }
        }