From 37f2b4db909b0716d5d261206d713abc1dd83fd0 Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Sat, 7 Jul 2012 17:32:19 +0000 Subject: [PATCH] * (bug #5709) Fix crash when invoked with --version --- code/sys/sys_main.c | 15 +++++++++++++-- code/sys/sys_unix.c | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/code/sys/sys_main.c b/code/sys/sys_main.c index dae8e8f6..70c9933f 100644 --- a/code/sys/sys_main.c +++ b/code/sys/sys_main.c @@ -140,7 +140,12 @@ Sys_PIDFileName */ static char *Sys_PIDFileName( void ) { - return va( "%s/%s", Sys_DefaultHomePath( ), PID_FILENAME ); + const char *homePath = Sys_DefaultHomePath( ); + + if( *homePath != NULL ) + return va( "%s/%s", Sys_DefaultHomePath( ), PID_FILENAME ); + + return NULL; } /* @@ -156,6 +161,9 @@ qboolean Sys_WritePIDFile( void ) FILE *f; qboolean stale = qfalse; + if( pidFile == NULL ) + return qfalse; + // First, check if the pid file is already there if( ( f = fopen( pidFile, "r" ) ) != NULL ) { @@ -204,7 +212,10 @@ static __attribute__ ((noreturn)) void Sys_Exit( int exitCode ) if( exitCode < 2 ) { // Normal exit - remove( Sys_PIDFileName( ) ); + char *pidFile = Sys_PIDFileName( ); + + if( pidFile != NULL ) + remove( pidFile ); } Sys_PlatformExit( ); diff --git a/code/sys/sys_unix.c b/code/sys/sys_unix.c index a60b0863..508383dd 100644 --- a/code/sys/sys_unix.c +++ b/code/sys/sys_unix.c @@ -53,7 +53,7 @@ char *Sys_DefaultHomePath(void) { char *p; - if( !*homePath ) + if( !*homePath && com_homepath != NULL ) { if( ( p = getenv( "HOME" ) ) != NULL ) {