Thank you for your reply to me rapidly.
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.
It seems that my opinion isn't understanded.My application program always uses GrDestroyPattern() after GrBuildPixmapBits() called.
In GrBuildPixmapFromBits(), there are two times creating of contexts; "cwork" and "result". a)"cwork" : working area for the function. User applications can not have access to "cwork" and, It isn't necessary for users to know to the "cwork" existing. So, "cwork" and the area concerned with it must be auto-destroyed at end of this function. Auto-variable"cwork" will be automatically destroyed, but "cwork->gp_pxp_source.gf_baseaddr==memory==mymem" from far heap will not be destroyed automatically.
struct "cwork" ; from stack== auto-variable *--memory ; from far heap
b)"result" : the result of calculating in this function. A pointer "result" is bringed to user applications as a return-value and the responsibility of the destroying of "result" moves to user applications too.
About (a) : GRX library must free the area.<-------This part contain the ploblem! About (b) : User application program must free it.
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
I understand that the condition of memory allocating are... A)from heap if where==NULL and from far heap if memory==NULL (that you mentioned ) B) only "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
So, this meets the above condition (B), then "memory" will be allocate from far heap. By reason of result!=&cwork, if I am willing to use GrDestroyPattern(), the apprication program can not free the local memory as "mymem"!
I don't think that this problem is my poor reading of GRX documentation. Do you think so or not?
Akira Watanabe