[openjk] 14/23: [MP] Properly close file handles in the case of errors. Also fixed some flag unsetting (EF_SOUNDTRACKER, WPFLAG_GOALPOINT)

Simon McVittie smcv at debian.org
Thu Jan 11 17:29:00 UTC 2018


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian/master
in repository openjk.

commit efbeb7cbbee591620932d053bb4a4f0131846538
Author: Razish <mrrazish at gmail.com>
Date:   Mon Dec 25 10:41:08 2017 +1100

    [MP] Properly close file handles in the case of errors. Also fixed some flag unsetting (EF_SOUNDTRACKER, WPFLAG_GOALPOINT)
---
 codemp/cgame/cg_event.c      |  2 +-
 codemp/cgame/cg_players.c    |  1 +
 codemp/cgame/cg_saga.c       |  7 +++++--
 codemp/game/NPC_stats.c      |  1 +
 codemp/game/ai_util.c        |  1 +
 codemp/game/ai_wpnav.c       |  7 ++++---
 codemp/game/bg_misc.c        | 28 ++++++----------------------
 codemp/game/bg_panimate.c    |  1 +
 codemp/game/bg_saberLoad.c   |  3 ++-
 codemp/game/bg_saga.c        | 14 ++++++++++----
 codemp/game/bg_vehicleLoad.c |  2 ++
 codemp/game/g_saga.c         |  7 +++++--
 codemp/game/g_utils.c        | 11 ++++-------
 codemp/ui/ui_force.c         |  1 +
 codemp/ui/ui_main.c          | 19 +++++++++++--------
 15 files changed, 55 insertions(+), 50 deletions(-)

diff --git a/codemp/cgame/cg_event.c b/codemp/cgame/cg_event.c
index bd10465..98d3992 100644
--- a/codemp/cgame/cg_event.c
+++ b/codemp/cgame/cg_event.c
@@ -3121,7 +3121,7 @@ void CG_EntityEvent( centity_t *cent, vec3_t position ) {
 		DEBUGNAME("EV_MUTE_SOUND");
 		if (cg_entities[es->trickedentindex2].currentState.eFlags & EF_SOUNDTRACKER)
 		{
-			cg_entities[es->trickedentindex2].currentState.eFlags -= EF_SOUNDTRACKER;
+			cg_entities[es->trickedentindex2].currentState.eFlags &= ~EF_SOUNDTRACKER;
 		}
 		trap->S_MuteSound(es->trickedentindex2, es->trickedentindex);
 		CG_S_StopLoopingSound(es->trickedentindex2, -1);
diff --git a/codemp/cgame/cg_players.c b/codemp/cgame/cg_players.c
index 1289716..6eac153 100644
--- a/codemp/cgame/cg_players.c
+++ b/codemp/cgame/cg_players.c
@@ -366,6 +366,7 @@ qboolean CG_ParseSurfsFile( const char *modelName, const char *skinName, char *s
 	if ( len >= sizeof( text ) - 1 )
 	{
 		Com_Printf( "File %s too long\n", sfilename );
+		trap->FS_Close( f );
 		return qfalse;
 	}
 
diff --git a/codemp/cgame/cg_saga.c b/codemp/cgame/cg_saga.c
index 7f3ebde..9d688fb 100644
--- a/codemp/cgame/cg_saga.c
+++ b/codemp/cgame/cg_saga.c
@@ -188,8 +188,11 @@ void CG_InitSiegeMode(void)
 
 	len = trap->FS_Open(levelname, &f, FS_READ);
 
-	if (!f || len >= MAX_SIEGE_INFO_SIZE)
-	{
+	if ( !f ) {
+		goto failure;
+	}
+	if ( len >= MAX_SIEGE_INFO_SIZE ) {
+		trap->FS_Close( f );
 		goto failure;
 	}
 
diff --git a/codemp/game/NPC_stats.c b/codemp/game/NPC_stats.c
index 0478405..4920ad8 100644
--- a/codemp/game/NPC_stats.c
+++ b/codemp/game/NPC_stats.c
@@ -3591,6 +3591,7 @@ void NPC_LoadParms( void )
 		else
 		{
 			if ( totallen + len >= MAX_NPC_DATA_SIZE ) {
+				trap->FS_Close( f );
 				trap->Error( ERR_DROP, "NPC extensions (*.npc) are too large" );
 			}
 			trap->FS_Read(npcParseBuffer, len, f);
diff --git a/codemp/game/ai_util.c b/codemp/game/ai_util.c
index 44bd157..03dc9bb 100644
--- a/codemp/game/ai_util.c
+++ b/codemp/game/ai_util.c
@@ -656,6 +656,7 @@ void BotUtilizePersonality(bot_state_t *bs)
 	{
 		trap->Print(S_COLOR_RED "Personality file exceeds maximum length\n");
 		B_TempFree(131072); //buf
+		trap->FS_Close( f );
 		return;
 	}
 
diff --git a/codemp/game/ai_wpnav.c b/codemp/game/ai_wpnav.c
index 992060f..562fe75 100644
--- a/codemp/game/ai_wpnav.c
+++ b/codemp/game/ai_wpnav.c
@@ -1886,7 +1886,7 @@ void CalculateWeightGoals(void)
 
 				if (gWPArray[i]->flags & WPFLAG_GOALPOINT)
 				{
-					gWPArray[i]->flags -= WPFLAG_GOALPOINT;
+					gWPArray[i]->flags &= ~WPFLAG_GOALPOINT;
 				}
 			}
 
@@ -2047,6 +2047,7 @@ int LoadPathData(const char *filename)
 	if (len >= 524288)
 	{
 		trap->Print(S_COLOR_RED "Route file exceeds maximum length\n");
+		trap->FS_Close( f );
 		return 0;
 	}
 
@@ -3709,11 +3710,11 @@ int AcceptBotCommand(char *cmd, gentity_t *pl)
 			{
 				if (gWPArray[i]->flags & WPFLAG_ONEWAY_FWD)
 				{
-					gWPArray[i]->flags -= WPFLAG_ONEWAY_FWD;
+					gWPArray[i]->flags &= ~WPFLAG_ONEWAY_FWD;
 				}
 				if (gWPArray[i]->flags & WPFLAG_ONEWAY_BACK)
 				{
-					gWPArray[i]->flags -= WPFLAG_ONEWAY_BACK;
+					gWPArray[i]->flags &= ~WPFLAG_ONEWAY_BACK;
 				}
 			}
 
diff --git a/codemp/game/bg_misc.c b/codemp/game/bg_misc.c
index 3ad8529..10668df 100644
--- a/codemp/game/bg_misc.c
+++ b/codemp/game/bg_misc.c
@@ -322,31 +322,15 @@ int WeaponAttackAnim[WP_NUM_WEAPONS] =
 	BOTH_ATTACK1//WP_TURRET,
 };
 
-qboolean BG_FileExists(const char *fileName)
-{
-	if (fileName && fileName[0])
-	{
-		int fh = 0;
-	#ifdef _GAME
-		trap->FS_Open(fileName, &fh, FS_READ);
-	#elif _CGAME
-		trap->FS_Open(fileName, &fh, FS_READ);
-	#elif UI_BUILD
-		trap->FS_Open(fileName, &fh, FS_READ);
-	#endif
-		if (fh > 0)
-		{
-		#ifdef _GAME
-			trap->FS_Close(fh);
-		#elif _CGAME
-			trap->FS_Close(fh);
-		#elif UI_BUILD
-			trap->FS_Close(fh);
-		#endif
+qboolean BG_FileExists( const char *fileName ) {
+	if ( fileName && fileName[0] ) {
+		fileHandle_t f = NULL_FILE;
+		trap->FS_Open( fileName, &f, FS_READ );
+		if ( f > 0 ) {
+			trap->FS_Close( f );
 			return qtrue;
 		}
 	}
-
 	return qfalse;
 }
 
diff --git a/codemp/game/bg_panimate.c b/codemp/game/bg_panimate.c
index 3f6b9be..fa65f9d 100644
--- a/codemp/game/bg_panimate.c
+++ b/codemp/game/bg_panimate.c
@@ -2375,6 +2375,7 @@ int BG_ParseAnimationFile(const char *filename, animation_t *animset, qboolean i
 		len = trap->FS_Open( filename, &f, FS_READ );
 		if ( (len <= 0) || (len >= sizeof( BGPAFtext ) - 1) )
 		{
+			trap->FS_Close( f );
 			if (dynAlloc)
 			{
 				BG_AnimsetFree(animset);
diff --git a/codemp/game/bg_saberLoad.c b/codemp/game/bg_saberLoad.c
index 75abd36..ae7460d 100644
--- a/codemp/game/bg_saberLoad.c
+++ b/codemp/game/bg_saberLoad.c
@@ -2281,12 +2281,13 @@ void WP_SaberLoadParms( void )
 
 		len = trap->FS_Open( va( "ext_data/sabers/%s", holdChar ), &f, FS_READ );
 
-		if ( len == -1 ) {
+		if ( !f ) {
 			Com_Printf( "WP_SaberLoadParms: error reading file: %s\n", holdChar );
 			continue;
 		}
 
 		if ( (totallen + len+1) >= MAX_SABER_DATA_SIZE ) {
+			trap->FS_Close( f );
 #ifdef UI_BUILD
 			Com_Error( ERR_FATAL, "WP_SaberLoadParms: Saber extensions (*.sab) are too large!\nRan out of space before reading %s", holdChar );
 #else
diff --git a/codemp/game/bg_saga.c b/codemp/game/bg_saga.c
index deaded4..d67e339 100644
--- a/codemp/game/bg_saga.c
+++ b/codemp/game/bg_saga.c
@@ -782,8 +782,11 @@ void BG_SiegeParseClassFile(const char *filename, siegeClassDesc_t *descBuffer)
 
 	len = trap->FS_Open( filename, &f, FS_READ );
 
-	if (!f || len >= 4096)
-	{
+	if (!f) {
+		return;
+	}
+	if (len >= 4096) {
+		trap->FS_Close( f );
 		return;
 	}
 
@@ -1265,8 +1268,11 @@ void BG_SiegeParseTeamFile(const char *filename)
 
 	len = trap->FS_Open(filename, &f, FS_READ);
 
-	if (!f || len >= 2048)
-	{
+	if (!f) {
+		return;
+	}
+	if (len >= 2048) {
+		trap->FS_Close( f );
 		return;
 	}
 
diff --git a/codemp/game/bg_vehicleLoad.c b/codemp/game/bg_vehicleLoad.c
index a14fb28..a77d3de 100644
--- a/codemp/game/bg_vehicleLoad.c
+++ b/codemp/game/bg_vehicleLoad.c
@@ -1320,6 +1320,7 @@ void BG_VehWeaponLoadParms( void )
 			}
 
 			if ( totallen + len >= MAX_VEH_WEAPON_DATA_SIZE ) {
+				trap->FS_Close( f );
 				Com_Error(ERR_DROP, "Vehicle Weapon extensions (*.vwp) are too large" );
 			}
 			strcat( marker, tempReadBuffer );
@@ -1386,6 +1387,7 @@ void BG_VehicleLoadParms( void )
 			}
 
 			if ( totallen + len >= MAX_VEHICLE_DATA_SIZE ) {
+				trap->FS_Close( f );
 				Com_Error(ERR_DROP, "Vehicle extensions (*.veh) are too large" );
 			}
 			strcat( marker, tempReadBuffer );
diff --git a/codemp/game/g_saga.c b/codemp/game/g_saga.c
index fcb8769..ce905ad 100644
--- a/codemp/game/g_saga.c
+++ b/codemp/game/g_saga.c
@@ -171,8 +171,11 @@ void InitSiegeMode(void)
 
 	len = trap->FS_Open(levelname, &f, FS_READ);
 
-	if (!f || len >= MAX_SIEGE_INFO_SIZE)
-	{
+	if (!f) {
+		goto failure;
+	}
+	if (len >= MAX_SIEGE_INFO_SIZE) {
+		trap->FS_Close( f );
 		goto failure;
 	}
 
diff --git a/codemp/game/g_utils.c b/codemp/game/g_utils.c
index 3ae79cc..bbda55a 100644
--- a/codemp/game/g_utils.c
+++ b/codemp/game/g_utils.c
@@ -721,11 +721,8 @@ static void G_SpewEntList(void)
 	char className[MAX_STRING_CHARS];
 	gentity_t *ent;
 	char *str;
-#ifdef FINAL_BUILD
-	#define VM_OR_FINAL_BUILD
-#endif
 
-#ifndef VM_OR_FINAL_BUILD
+#ifdef _DEBUG
 	fileHandle_t fh;
 	trap->FS_Open("entspew.txt", &fh, FS_WRITE);
 #endif
@@ -753,7 +750,7 @@ static void G_SpewEntList(void)
 
 				str = va("TEMPENT %4i: EV %i\n", ent->s.number, ent->s.eType-ET_EVENTS);
 				Com_Printf(str);
-#ifndef VM_OR_FINAL_BUILD
+#ifdef _DEBUG
 				if (fh)
 				{
 					trap->FS_Write(str, strlen(str), fh);
@@ -771,7 +768,7 @@ static void G_SpewEntList(void)
 			}
 			str = va("ENT %4i: Classname %s\n", ent->s.number, className);
 			Com_Printf(str);
-#ifndef VM_OR_FINAL_BUILD
+#ifdef _DEBUG
 			if (fh)
 			{
 				trap->FS_Write(str, strlen(str), fh);
@@ -784,7 +781,7 @@ static void G_SpewEntList(void)
 
 	str = va("TempEnt count: %i\nTempEnt ST: %i\nNPC count: %i\nProjectile count: %i\n", numTempEnt, numTempEntST, numNPC, numProjectile);
 	Com_Printf(str);
-#ifndef VM_OR_FINAL_BUILD
+#ifdef _DEBUG
 	if (fh)
 	{
 		trap->FS_Write(str, strlen(str), fh);
diff --git a/codemp/ui/ui_force.c b/codemp/ui/ui_force.c
index b5a2676..898ad36 100644
--- a/codemp/ui/ui_force.c
+++ b/codemp/ui/ui_force.c
@@ -1202,6 +1202,7 @@ void UI_ForceConfigHandle( int oldindex, int newindex )
 
 	if (len >= 8192)
 	{
+		trap->FS_Close( f );
 		return;
 	}
 
diff --git a/codemp/ui/ui_main.c b/codemp/ui/ui_main.c
index ad767d8..94f67a7 100644
--- a/codemp/ui/ui_main.c
+++ b/codemp/ui/ui_main.c
@@ -322,14 +322,13 @@ int UI_ParseAnimationFile(const char *filename, animation_t *animset, qboolean i
 	if (!UIPAFtextLoaded || !isHumanoid)
 	{ //rww - We are always using the same animation config now. So only load it once.
 		len = trap->FS_Open( filename, &f, FS_READ );
-		if ( (len <= 0) || (len >= sizeof( UIPAFtext ) - 1) )
-		{
-			if (len > 0)
-			{
-				Com_Error(ERR_DROP, "%s exceeds the allowed ui-side animation buffer!", filename);
-			}
+		if ( !f ) {
 			return -1;
 		}
+		if ( len >= sizeof( UIPAFtext ) - 1 ) {
+			trap->FS_Close( f );
+			Com_Error(ERR_DROP, "%s exceeds the allowed ui-side animation buffer!", filename);
+		}
 
 		trap->FS_Read( UIPAFtext, len, f );
 		UIPAFtext[len] = 0;
@@ -7125,8 +7124,11 @@ void UI_SetSiegeTeams(void)
 
 	len = trap->FS_Open(levelname, &f, FS_READ);
 
-	if (!f || len >= MAX_SIEGE_INFO_SIZE)
-	{
+	if (!f) {
+		return;
+	}
+	if (len >= MAX_SIEGE_INFO_SIZE) {
+		trap->FS_Close( f );
 		return;
 	}
 
@@ -9703,6 +9705,7 @@ static void UI_BuildPlayerModel_List( qboolean inGameLoad )
 			buffer = malloc(filelen + 1);
 			if(!buffer)
 			{
+				trap->FS_Close( f );
 				Com_Error(ERR_FATAL, "Could not allocate buffer to read %s", fpath);
 			}
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/openjk.git



More information about the Pkg-games-commits mailing list