Skip to content

Commit

Permalink
Repair of the infamous gzip memory leak.
Browse files Browse the repository at this point in the history
  • Loading branch information
vermaseren committed Dec 13, 2017
1 parent a484c0a commit 4493f01
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions sources/compress.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ int SetupOutputGZIP(FILEHANDLE *f)
/*
6: Initiate the deflation
*/

if ( deflateInit(f->zsp,AR.gzipCompress) != Z_OK ) {
MLOCK(ErrorMessageLock);
MesPrint("Error from zlib: %s",f->zsp->msg);
Expand Down
1 change: 1 addition & 0 deletions sources/setfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ SORTING *AllocSort(LONG LargeSize, LONG SmallSize, LONG SmallEsize, LONG TermsIn
#ifdef WITHZLIB
/* sort->file.ziosize = IOsize; */
sort->file.ziosize = IObuffersize*sizeof(WORD);
sort->file.ziobuffer = 0;
#endif
if ( AM.S0 != 0 ) {
sort->file.name = (char *)(sort->file.PObuffer + IObuffersize);
Expand Down
14 changes: 12 additions & 2 deletions sources/sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ LONG EndSort(PHEAD WORD *buffer, int par)
#ifdef WITHZLIB
{ int oldgzipCompress = AR.gzipCompress;
AR.gzipCompress = 0;
/* SetupOutputGZIP(fout); */
#endif
if ( tover > 0 ) {
ss = S->sPointer;
Expand Down Expand Up @@ -1414,9 +1413,12 @@ WORD PutOut(PHEAD WORD *term, POSITION *position, FILEHANDLE *fi, WORD ncomp)
fi->handle = (WORD)RetCode;
PUTZERO(fi->filesize);
PUTZERO(fi->POposition);
/*
Should not be here anymore?
#ifdef WITHZLIB
fi->ziobuffer = 0;
#endif
*/
}
else {
MLOCK(ErrorMessageLock);
Expand Down Expand Up @@ -1628,9 +1630,12 @@ WORD PutOut(PHEAD WORD *term, POSITION *position, FILEHANDLE *fi, WORD ncomp)
fi->handle = (WORD)RetCode;
PUTZERO(fi->filesize);
PUTZERO(fi->POposition);
/*
Should not be here?
#ifdef WITHZLIB
fi->ziobuffer = 0;
#endif
*/
}
else {
MLOCK(ErrorMessageLock);
Expand Down Expand Up @@ -1762,9 +1767,12 @@ WORD FlushOut(POSITION *position, FILEHANDLE *fi, int compr)
PUTZERO(fi->filesize);
PUTZERO(fi->POposition);
fi->handle = (WORD)RetCode;
/*
Should not be here?
#ifdef WITHZLIB
fi->ziobuffer = 0;
#endif
*/
}
else {
MLOCK(ErrorMessageLock);
Expand Down Expand Up @@ -3548,9 +3556,12 @@ WORD MergePatches(WORD par)
fout->handle = fhandle;
PUTZERO(fout->filesize);
PUTZERO(fout->POposition);
/*
Should not be here?
#ifdef WITHZLIB
fout->ziobuffer = 0;
#endif
*/
#ifdef ALLLOCK
LOCK(fout->pthreadslock);
#endif
Expand Down Expand Up @@ -3736,7 +3747,6 @@ WORD MergePatches(WORD par)
#define FRONTSIZE (2*AM.MaxTer)
WORD *copybuf = (WORD *)(((UBYTE *)(S->sBuffer)) + FRONTSIZE);
WORD *copytop;
SetupOutputGZIP(fout);
SetupAllInputGZIP(S);
m1 = m2 = copybuf;
position2 = S->iPatches[0];
Expand Down
2 changes: 2 additions & 0 deletions sources/startup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,8 @@ WORD IniVars()
AM.gOutNumberType = RATIONALMODE;
#ifdef WITHZLIB
AR.gzipCompress = GZIPDEFAULT;
AR.FoStage4[0].ziobuffer = 0;
AR.FoStage4[1].ziobuffer = 0;
#endif
AR.BracketOn = 0;
AC.bracketindexflag = 0;
Expand Down
2 changes: 2 additions & 0 deletions sources/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ ALLPRIVATES *InitializeOneThread(int identity)
#ifdef WITHZLIB
AR.FoStage4[0].ziosize = IOsize;
AR.FoStage4[1].ziosize = IOsize;
AR.FoStage4[0].ziobuffer = 0;
AR.FoStage4[1].ziobuffer = 0;
#endif
AR.FoStage4[0].POsize = ((IOsize+sizeof(WORD)-1)/sizeof(WORD))*sizeof(WORD);
AR.FoStage4[1].POsize = ((IOsize+sizeof(WORD)-1)/sizeof(WORD))*sizeof(WORD);
Expand Down

0 comments on commit 4493f01

Please sign in to comment.