From 0f1b59fc0585e79306eb5beb28822cb5e12a57dc Mon Sep 17 00:00:00 2001 From: Tim Angus Date: Sat, 7 Jul 2012 17:32:19 +0000 Subject: * (bug #5709) Fix crash when invoked with --version --- src/sys/sys_main.c | 15 +++++++++++++-- src/sys/sys_unix.c | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/sys/sys_main.c b/src/sys/sys_main.c index 170107ae..bfec88eb 100644 --- a/src/sys/sys_main.c +++ b/src/sys/sys_main.c @@ -141,7 +141,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; } /* @@ -157,6 +162,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 ) { @@ -205,7 +213,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/src/sys/sys_unix.c b/src/sys/sys_unix.c index 53a86354..b05cf855 100644 --- a/src/sys/sys_unix.c +++ b/src/sys/sys_unix.c @@ -54,7 +54,7 @@ char *Sys_DefaultHomePath(void) { char *p; - if( !*homePath ) + if( !*homePath && com_homepath != NULL ) { if( ( p = getenv( "HOME" ) ) != NULL ) { -- cgit