Skip to content

Commit

Permalink
Fix missing fcloses on failures (#5143)
Browse files Browse the repository at this point in the history
  • Loading branch information
gogglesguy authored and tbonfort committed Sep 8, 2015
1 parent 75d092a commit de2869b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mapimageio.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,13 @@ int readPalette(const char *palette, rgbaPixel *entries, unsigned int *nEntries,
continue; /* skip comments and blank lines */
if(!useAlpha) {
if(3 != sscanf(buffer,"%d,%d,%d\n",&r,&g,&b)) {
fclose(stream);
msSetError(MS_MISCERR,"failed to parse color %d r,g,b triplet in line \"%s\" from file %s","readPalette()",*nEntries+1,buffer,palette);
return MS_FAILURE;
}
} else {
if(4 != sscanf(buffer,"%d,%d,%d,%d\n",&r,&g,&b,&a)) {
fclose(stream);
msSetError(MS_MISCERR,"failed to parse color %d r,g,b,a quadruplet in line \"%s\" from file %s","readPalette()",*nEntries+1,buffer,palette);
return MS_FAILURE;
}
Expand Down Expand Up @@ -1090,6 +1092,7 @@ int msLoadMSRasterBufferFromFile(char *path, rasterBufferObj *rb)
return MS_FAILURE;
}
if(1 != fread(signature,8,1,stream)) {
fclose(stream);
msSetError(MS_MISCERR, "Unable to read header from image file %s", "msLoadMSRasterBufferFromFile()",path);
return MS_FAILURE;
}
Expand Down
1 change: 1 addition & 0 deletions mapjoin.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ int msCSVJoinConnect(layerObj *layer, joinObj *join)
rewind(stream);

if((joininfo->rows = (char ***) malloc(joininfo->numrows*sizeof(char **))) == NULL) {
fclose(stream);
msSetError(MS_MEMERR, "Error allocating rows.", "msCSVJoinConnect()");
return(MS_FAILURE);
}
Expand Down
1 change: 1 addition & 0 deletions mapshape.c
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ SHPHandle msSHPOpen( const char * pszLayer, const char * pszAccess )
psSHP->fpSHX = fopen(pszFullname, pszAccess );
}
if( psSHP->fpSHX == NULL ) {
fclose(psSHP->fpSHP);
msFree(pszBasename);
msFree(pszFullname);
msFree(psSHP);
Expand Down
2 changes: 2 additions & 0 deletions mapv8.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ static Handle<Value> msV8ReadFile(V8Context *v8context, const char *path)
for (int i = 0; i < size;) {
int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
if (read == 0) {
delete [] chars;
fclose(file);
msDebug("msV8ReadFile: error while reading file '%s'\n", path);
return Undefined();
}
Expand Down

0 comments on commit de2869b

Please sign in to comment.