Hello GRX 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);
}
------------- * ------------
Do you think that my pointing out a bug is correct?
with greetings,
Akira Watanabe
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Akira Watanabe
A Electronics Engineer in a motor company