*/}}
فهرست منبع

Fixed remaining apparent leaks presumably

Yiming Wu 2 سال پیش
والد
کامیت
25e6f208a9
4فایلهای تغییر یافته به همراه38 افزوده شده و 13 حذف شده
  1. 2 2
      source/lagui/la_data.c
  2. 10 8
      source/lagui/la_kernel.c
  3. 24 0
      source/lagui/la_tns_kernel.c
  4. 2 3
      source/lagui/resources/la_operators.c

+ 2 - 2
source/lagui/la_data.c

@@ -3600,7 +3600,7 @@ void laRefreshUDFResourcesIn(char* rootpath){
     int len=strlen(rootpath);
     if (rootpath[len - 1] != '/') strcat(rootpath, "/");
 
-    struct dirent **NameList;
+    struct dirent **NameList=0;
     int NumFiles=scandir(rootpath,&NameList,0,alphasort);
 
     for(int i=0;i<NumFiles;i++){
@@ -3617,7 +3617,7 @@ void laRefreshUDFResourcesIn(char* rootpath){
             }
         }
     }
-    for (int i=0;i<NumFiles;i++){ free(NameList[i]); }
+    for (int i=0;i<NumFiles;i++){ free(NameList[i]); } if(NameList) free(NameList);
 
     if(NumFiles>=0){
         laListHandle additionals={0}; laSafeString* s;

+ 10 - 8
source/lagui/la_kernel.c

@@ -127,6 +127,8 @@ void la_DestroyWindow(laWindow *wnd){
     laLayout *l; laPanel *p;
 
     if (!wnd) return;
+    
+    la_StopAllOperators();
 
     strSafeDestroy(&wnd->Title);
 
@@ -265,6 +267,8 @@ int laGetReady(){
 
     MAIN.xvi=glXGetVisualFromFBConfig(MAIN.dpy, MAIN.BestFBC);
 
+    free(fbconfig);
+
     root = DefaultRootWindow(MAIN.dpy);
     if ((MAIN.cmap = XCreateColormap(MAIN.dpy, root, MAIN.xvi->visual, AllocNone)) == 0){
         printf("\n\tcannot create colormap\n\n"); exit(0);
@@ -427,14 +431,15 @@ void laShutoff(){
     strSafeDump();
 
     memNoLonger();
+
+    glXDestroyContext(MAIN.dpy,MAIN.glc);
 }
 
 //MSG====================================================
 
 int la_IsThisSysWindow(laWindow *wnd, Window hwnd){
     if (wnd->win == hwnd) return 1;
-    else
-        return 0;
+    else return 0;
 };
 void la_EnsurePanelSnapping(laPanel *p, int CW, int CH){
     if (p->SL){ int s=p->SL<0?0:p->SL;
@@ -5944,8 +5949,7 @@ void la_StopAllOperators(){
         if (!ai->Using){
             laOperator *dai = ai;
             la_DestroyOperator(&dai, &MAIN.CurrentWindow->Operators, 1);
-        }else
-            ai->StopNow = 1;
+        }else ai->StopNow = 1;
     }
 }
 
@@ -6208,11 +6212,9 @@ int la_HandleEvents(laWindow *w){
 
             e = lstPopItem(&w->EventList);
 
-            if (e && !w->Operators.pFirst){
-                laInvokeUi(0, "LA_window_operator", e, w, 0, 0);
-            }
+            if (e && !w->Operators.pFirst){ laInvokeUi(0, "LA_window_operator", e, w, 0, 0); }
 
-            if (e) if(!la_HandleSingleEvent(e, &w->Operators)) return 0; //EXIT
+            if (e) if(!la_HandleSingleEvent(e, &w->Operators)){ la_StopAllOperators(); return 0; } //EXIT
 
             FreeMem(e);
         }

+ 24 - 0
source/lagui/la_tns_kernel.c

@@ -1440,10 +1440,17 @@ void tnsDeleteBuiltinShaders(){
     tnsDeleteShaderProgram(T->immShader); T->immShader=0;
     tnsDeleteShaderProgram(T->TEST_MatcapShader); T->TEST_MatcapShader=0;
     tnsDeleteShaderProgram(T->TransparentGridShader); T->TransparentGridShader=0;
+    tnsDeleteShaderProgram(T->SelectionShader); T->SelectionShader=0;
+    tnsDeleteShaderProgram(T->SceneShader); T->SceneShader=0;
+    tnsDeleteShaderProgram(T->ShadowShader); T->ShadowShader=0;
+    tnsDeleteShaderProgram(T->RayShader); T->RayShader=0;
 }
 void tnsQuit(){
+    tnsQuitFontManager();
+
     tnsDeleteBuiltinShaders();
 
+    tnsOffscreen* off; while(off=T->Offscreens.pFirst){ tnsDelete2DOffscreen(off); }
     tnsTexture* t; while(t=T->Textures.pFirst){ tnsDeleteTexture(t); }
     
     arrFree(&T->Vert, &T->MaxVert);
@@ -1451,6 +1458,7 @@ void tnsQuit(){
     arrFree(&T->Normal, &T->MaxNormal);
     arrFree(&T->TexCoord, &T->MaxTexCoord);
     arrFree(&T->Index, &T->MaxIndex);
+    arrFree(&T->DrawingCommand, &T->DrawingCommand);
 
     glDeleteBuffers(1, &T->VertBufObject);
     glDeleteBuffers(1, &T->ColorBufObject);
@@ -2578,6 +2586,19 @@ tnsFontManager *FM;
 void tnsSetuptnsFontManager(){
     FM = CreateNew(tnsFontManager);
 };
+void tnsQuitFontManager(){
+    tnsInvalidateFontCache();
+    tnsFont*f=FM->UsingFont;
+    for(int i=0;i<f->NumFaces;i++){
+        FT_Done_Face(f->ftface[i]);
+    }
+    if(f->ftfacemono) FT_Done_Face(f->ftfacemono);
+    FT_Done_FreeType(f->ftlib);
+    free(f->characters);
+    free(f->monocharacters);
+    free(f);
+    FreeMem(FM);
+}
 
 int next_p2(int a){
     int rval = 1;
@@ -2603,6 +2624,7 @@ int tnsInvalidateFontCache(){
         if (FT_Load_Char(f->ftfacemono, 'a', FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP)||
             FT_Get_Glyph(f->ftfacemono->glyph, &glyph)){ SEND_PANIC_ERROR("Monospace font doesn't contain character 'a'"); }
         f->MonoAdvance=f->ftfacemono->glyph->advance.x/64.0;
+        if(glyph) FT_Done_Glyph(glyph);
     }
 }
 tnsFontSingleCharacter *tfntFetchCharTextureIDW(uint32_t ch, int UseMono);
@@ -2627,6 +2649,7 @@ void tnsLoadSystemFontMono(char* mono){
         if (FT_Load_Char(f->ftfacemono, 'a', FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP)||
             FT_Get_Glyph(f->ftfacemono->glyph, &glyph)){ SEND_PANIC_ERROR("Monospace font doesn't contain character 'a'"); }
         f->MonoAdvance=f->ftfacemono->glyph->advance.x/64.0;
+        if(glyph) FT_Done_Glyph(glyph);
     }
 };
 void tnsLoadSystemFont(int num_fonts, ...){
@@ -2844,6 +2867,7 @@ tnsFontSingleCharacter *tfntFetchCharTextureIDW(uint32_t ch, int UseMono){
     glTexSubImage2D(GL_TEXTURE_2D, 0, fsc->bufferx, fsc->buffery, w, h, GL_RED, GL_UNSIGNED_BYTE, buf);
 
     FreeMem(buf);
+    FT_Done_Glyph(glyph);
 
     fsc->Generated = 1;
     return fsc;

+ 2 - 3
source/lagui/resources/la_operators.c

@@ -168,7 +168,7 @@ void la_FileBrowserRebuildList(laFileBrowser *fb){
 
     if (fb->Path[len - 1] != L'/') strcat(fb->Path, "/");
     
-    struct dirent **NameList;
+    struct dirent **NameList=0;
     int NumFiles=scandir(fb->Path,&NameList,0,alphasort);
 
     while (fi = lstPopItem(&fb->FileList))
@@ -207,8 +207,7 @@ void la_FileBrowserRebuildList(laFileBrowser *fb){
 
     lstCombineLists(&fb->FileList, &Files);
     
-    for (int i=0;i<NumFiles;i++){ free(NameList[i]); }
-    free(NameList);
+    for (int i=0;i<NumFiles;i++){ free(NameList[i]); } free(NameList);
 
     while (dl = lstPopItem(&fb->Disks))
         memFree(dl);