Skip to content

Commit fc66184

Browse files
committed
Added more fixes
Added more fixes guided by @xezon suggestions, thank you. Removed `goto` blocks that I created, maintained original `goto` blocks as this is only to fix leaks, not modernize the algorithms. Signed-off-by: Victor Matia <[email protected]>
1 parent 2e15701 commit fc66184

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Core/Libraries/Source/Compression/LZHCompress/NoxCompress.cpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ Bool DecompressFile (char *infile, char *outfile)
6969
outBlock= (char *) DbgMalloc( rawSize );
7070

7171
if (( inBlock == NULL ) || ( outBlock == NULL ))
72-
goto free_error;
72+
{
73+
if (inBlock) DbgFree(inBlock);
74+
if (outBlock) DbgFree(outBlock);
75+
return FALSE;
76+
}
7377

7478
// Read in a big chunk o file
7579
NoxRead(inBlock, 1, compressedSize, inFilePtr);
@@ -105,18 +109,16 @@ Bool DecompressFile (char *infile, char *outfile)
105109
fclose(outFilePtr);
106110
}
107111
else
108-
goto free_error;
112+
{
113+
if (inBlock) DbgFree(inBlock);
114+
if (outBlock) DbgFree(outBlock);
115+
return FALSE;
116+
}
109117

110118
// Clean up this mess
111119
DbgFree(inBlock);
112120
DbgFree(outBlock);
113121
return TRUE;
114-
115-
free_error:
116-
// Clean up this mess
117-
if (inBlock) DbgFree(inBlock);
118-
if (outBlock) DbgFree(outBlock);
119-
return FALSE;
120122
} // End of if fileptr
121123

122124
return FALSE;
@@ -137,7 +139,11 @@ Bool CompressFile (char *infile, char *outfile)
137139
// Parameter checking
138140

139141
if (( infile == NULL ) || ( outfile == NULL ))
142+
{
143+
if (infile) DbgFree(infile);
144+
if (outfile) DbgFree(outfile);
140145
return FALSE;
146+
}
141147

142148
// Allocate the appropriate amount of memory
143149
inFilePtr = fopen( infile, "rb" );
@@ -153,7 +159,11 @@ Bool CompressFile (char *infile, char *outfile)
153159
outBlock= (char *) DbgMalloc( LZHLCompressorCalcMaxBuf( rawSize ));
154160

155161
if (( inBlock == NULL ) || ( outBlock == NULL ))
162+
{
163+
DbgFree(inBlock);
164+
DbgFree(outBlock);
156165
return FALSE;
166+
}
157167

158168
// Read in a big chunk o file
159169
NoxRead(inBlock, 1, rawSize, inFilePtr);
@@ -180,7 +190,11 @@ Bool CompressFile (char *infile, char *outfile)
180190
fclose(outFilePtr);
181191
}
182192
else
193+
{
194+
DbgFree(inBlock);
195+
DbgFree(outBlock);
183196
return FALSE;
197+
}
184198

185199
// Clean up
186200
DbgFree(inBlock);

0 commit comments

Comments
 (0)