X-Moto

Tasklist

FS#766 - [patch] Leaks founded by cppcheck static analyser for XMoto 0.5.4

Attached to Project: X-Moto
Opened by Anonymous Submitter - Friday, 07 January 2011, 16:32 GMT
Last edited by tuhoojabotti (tuhoojabotti) - Thursday, 03 February 2011, 11:54 GMT
Task Type Bug Report
Category General
Status Unconfirmed
Assigned To Nicolas Adenis-Lamarre (aspegic500)
Operating System All
Severity Medium
Priority Normal
Reported Version 0.5.4
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No

Details

Leaks founded by cppcheck (http://cppcheck.sourceforge.net/):
[./Replay.cpp:784]: (error) Memory leak: pRpl
[./Sound.cpp:168]: (error) Memory leak: pSample
[./WWW.cpp:209]: (error) Resource leak: v_destinationFile
[./WWW.cpp:323]: (error) Resource leak: v_destinationFile
[./WWW.cpp:481]: (error) Resource leak: v_destinationFile
[./WWW.cpp:631]: (error) Resource leak: v_destinationFile
[./xdgbasedir/src/basedir.c:314]: (error) Memory leak: home

Patch for fix this errors:

Index: src/WWW.cpp
===================================================================
--- src/WWW.cpp (revision 3245)
+++ src/WWW.cpp (working copy)
@@ -205,7 +205,7 @@
std::string v_www_agent = WWW_AGENT;

/* open the file */
- if( (v_destinationFile = fopen(v_local_file_tmp.c_str(), "wb")) == false) {
+ if( (v_destinationFile = fopen(v_local_file_tmp.c_str(), "wb")) == NULL) {
throw Exception("error : unable to open output file "
+ v_local_file_tmp);
}
@@ -319,7 +319,7 @@
LogInfo(std::string("Uploading replay " + p_replayFilename).c_str());

/* open the file */
- if( (v_destinationFile = fopen(v_local_file.c_str(), "wb")) == false) {
+ if( (v_destinationFile = fopen(v_local_file.c_str(), "wb")) == NULL) {
throw Exception("error : unable to open output file " DEFAULT_WWW_MSGFILE);
}

@@ -477,7 +477,7 @@
LogInfo(std::string("Sending vote").c_str());

/* open the file */
- if( (v_destinationFile = fopen(v_local_file.c_str(), "wb")) == false) {
+ if( (v_destinationFile = fopen(v_local_file.c_str(), "wb")) == NULL) {
throw Exception("error : unable to open output file " DEFAULT_WWW_MSGFILE);
}

@@ -627,7 +627,7 @@
LogInfo(std::string("Uploading dbsync " + p_dbSyncFilename + " to " + p_url_to_transfert).c_str());

/* open the file */
- if( (v_destinationFile = fopen(p_answerFile.c_str(), "wb")) == false) {
+ if( (v_destinationFile = fopen(p_answerFile.c_str(), "wb")) == NULL) {
throw Exception("error : unable to open output file " + p_answerFile);
}

Index: src/Sound.cpp
===================================================================
--- src/Sound.cpp (revision 3245)
+++ src/Sound.cpp (working copy)
@@ -165,6 +165,7 @@
FileHandle *pf = XMFS::openIFile(FDT_DATA, File);
if(pf == NULL) {
SDL_FreeRW(pOps);
+ delete pSample;
throw Exception("failed to open sample file " + File);
}

Index: src/Replay.cpp
===================================================================
--- src/Replay.cpp (revision 3245)
+++ src/Replay.cpp (working copy)
@@ -770,7 +770,6 @@
return NULL;
}

- ReplayInfo *pRpl = new ReplayInfo;
std::string LevelID;
std::string Player;
bool bFinished = true;
@@ -799,7 +798,8 @@
finishTime = GameApp::floatToTime(XMFS::readFloat_LE(pfh));
break;
}
-
+
+ ReplayInfo *pRpl = new ReplayInfo;
/* Set members */
pRpl->Level = LevelID;
pRpl->Name = p_ReplayName;
Index: src/xdgbasedir/src/basedir.c
===================================================================
--- src/xdgbasedir/src/basedir.c (revision 3245)
+++ src/xdgbasedir/src/basedir.c (working copy)
@@ -311,19 +311,38 @@
/* Allocate maximum needed for any of the 3 default values */
defVal = (char*)malloc(strlen(home)+
MAX(MAX(sizeof(DefaultRelativeDataHome), sizeof(DefaultRelativeConfigHome)), sizeof(DefaultRelativeCacheHome)));
- if (!defVal) return FALSE;
+ if (!defVal)
+ {
+ free(home);
+ return FALSE;
+ }

strcpy(defVal, home);
strcat(defVal, DefaultRelativeDataHome);
- if (!(cache->dataHome = xdgGetEnv("XDG_DATA_HOME", defVal))) return FALSE;
+ if (!(cache->dataHome = xdgGetEnv("XDG_DATA_HOME", defVal)))
+ {
+ free(defVal);
+ free(home);
+ return FALSE;
+ }

defVal[strlen(home)] = 0;
strcat(defVal, DefaultRelativeConfigHome);
- if (!(cache->configHome = xdgGetEnv("XDG_CONFIG_HOME", defVal))) return FALSE;
+ if (!(cache->configHome = xdgGetEnv("XDG_CONFIG_HOME", defVal)))
+ {
+ free(defVal);
+ free(home);
+ return FALSE;
+ }

defVal[strlen(home)] = 0;
strcat(defVal, DefaultRelativeCacheHome);
- if (!(cache->cacheHome = xdgGetEnv("XDG_CACHE_HOME", defVal))) return FALSE;
+ if (!(cache->cacheHome = xdgGetEnv("XDG_CACHE_HOME", defVal)))
+ {
+ free(defVal);
+ free(home);
+ return FALSE;
+ }

free(defVal);
free(home);
This task depends upon

Loading...