Mail Archives: djgpp/1999/10/04/14:15:45
From: | "Uncle(Akira Watanabe)" <akira_wata AT email DOT msn DOT com>
|
Subject: | A memory leak found.
|
Date: | Tue, 5 Oct 1999 00:15:52 +0900
|
Lines: | 79
|
MIME-Version: | 1.0
|
X-Newsreader: | Microsoft Outlook Express 5.00.2014.211
|
X-MimeOLE: | Produced By Microsoft MimeOLE V5.00.2014.211
|
Message-ID: | <#JchTpnD$GA.338@cpmsnbbsa05>
|
Newsgroups: | comp.os.msdos.djgpp
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Hello GRX DJGPP freaks,
I think that GRX is good library and very usefull.
Bug in GrBuildPixmapFromBits() of GRX2.2 and 2.3 found
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This problem is a memory leak.
In GrBuildPixmapFromBits(), a temporaly context area is allocated from the
heap-area
by GrCreateContext(). But,the temporaly area isn't deallocated after
this and the area is missing by the application program, because the "cwork"
variable is a Auto-variable, and is destroyed at the end of this function.
When you
have a large memory or call this function at a few times by a your program
running, this bug dose not cause the abnomal excution of the program.
The GrBuildPixmapFromBits() function is found in makepat.c
Fixing the bug is easy, the following source in src/pattern/makepat.c:
(I added the ~~~~~~-line part in the follow.)
GrPattern *GrBuildPixmapFromBits(char *bits,int w,int h,GrColor fgc,GrColor
bgc)
{
GrContext csave,cwork;
GrPixmap *result;
unsigned char *src;
int wdt,wdt2,fullw;
int hgt,mask,byte;
if((fullw = _GrBestPixmapWidth(w,h)) <= 0) return(NULL);
result = (GrPixmap *)malloc(sizeof(GrPixmap));
if(result == NULL) return(NULL);
if (!GrCreateContext(fullw,h,NULL,&cwork)) { // "NULL" means that internal
area is secured
free(result);
return NULL;
}
csave = *CURC;
*CURC = cwork;
fgc &= C_COLOR;
bgc &= C_COLOR;
for(hgt = 0; hgt < h; hgt++) {
for(wdt2 = fullw; (wdt2 -= w) >= 0; ) {
src = (unsigned char *)bits;
mask = byte = 0;
for(wdt = w; --wdt >= 0; ) {
if((mask >>= 1) == 0) { mask = 0x80; byte = *src++; }
(*CURC->gc_driver->drawpixel)(wdt2+wdt,hgt,((byte & mask) ? fgc :
bgc));
}
}
bits += (w + 7) >> 3;
}
*CURC = csave;
result->pxp_source = cwork.gc_frame;
result->pxp_source.gf_memflags = (GCM_MYCONTEXT | GCM_MYMEMORY);
result->pxp_ispixmap = TRUE;
result->pxp_width = fullw;
result->pxp_height = h;
result->pxp_oper = 0;
GrDestroyContex(&cwork); // 990923 added by A.Watanabe.
// ~~~~~~~~~~~~~~~~~~~~~~~*----The above line added.
return((GrPattern *)result);
}
------------- * ------------
If my pointing out a bug is correct, please could this fix applied in the
next release?
with greetings,
Akira Watanabe
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Akira Watanabe
A Electronics Engineer in a motor company
- Raw text -