GHOST cleanup (null check before delete, and 0 -> NULL for pointers).

Based on patch from Lawrence D'Oliveiro (ldo) in T48499.
This commit is contained in:
Bastien Montagne 2016-05-24 11:47:48 +02:00
parent 0b588f0905
commit a7c3ec4feb
Notes: blender-bot 2023-02-14 10:54:29 +01:00
Referenced by issue #48508, Cycles Regression / Crash
12 changed files with 42 additions and 46 deletions

View 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) {

View 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;
}

View 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;

View 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;

View 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;
}

View 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];

View 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;

View 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;

View File

@ -106,7 +106,7 @@ public:
* \return The validity of the window.
*/
virtual bool getValid() const {
return m_context != 0;
return m_context != NULL;
}
/**

View 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

View 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;
}
}

View 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;
}
}