On Sun, 10 Oct 1999, Uncle(Akira Watanabe) wrote:
Hello GRX freaks,
I think that GRX is good library and very usefull.
Thanks.
Bug in GrBuildPixmapFromBits() of GRX2.2 and 2.3 found
This problem is a memory leak.
Well, it looks like the code is alright, see below.
In GrBuildPixmapFromBits(), a temporaly context area is allocated from the heap-area by GrCreateContext().
GrCreateContext() maps to GrCreateFrameContext() in setup/context.c:
GrContext *GrCreateFrameContext(GrFrameMode md,int w,int h,char far *memory[4],GrContext *where) { [...] if(!where) { where = malloc(sizeof(GrContext)); if(!where) return(NULL); flags = MYCONTEXT; } sttzero(where); if(!memory) { for(ii = 0; ii < fd->num_planes; ii++) { mymem[ii] = farmalloc((size_t)psize); if(!mymem[ii]) { while(--ii >= 0) farfree(mymem[ii]); if(flags) free(where); return(NULL); } } while(ii < 4) mymem[ii++] = NULL; memory = mymem; flags |= MYFRAME; }
So, memory will be allocated from heap if where==NULL and from far heap if memory==NULL
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
This means that only frame memory will be allocated since where == &cwork != NULL
few lines later:
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; return((GrPattern *)result);
The memory in the gc_frame section of the cwork context is moved to the new created GrPattern and flags are set up so GrDestoryPattern will release the memory: (GCM_MYCONTEXT | GCM_MYMEMORY)
Do you think that my pointing out a bug is correct?
Sorry to say, but it looks like thereŽs no bug here. The memory leak occurs in the user programm if GrDestroyPattern() isnŽt called.
Clear problem of missing documentation :(
Hartmut