[MPlayer-dev-eng] [PATCH] memory leak in demux_avs.c

Gianluigi Tiesi mplayer at netfarm.it
Mon May 23 20:38:19 CEST 2005


This should be enough without touching loader/ldt_keeper,
please test and apply :)

Works fine for me, I'll just need to test avs_demuxer -> then -> codec
using win32 to see if Release makes some problem.

Bye


-- 
Gianluigi Tiesi <sherpya at netfarm.it>
EDP Project Leader
Netfarm S.r.l. - http://www.netfarm.it/
Free Software: http://oss.netfarm.it/
-------------- next part --------------
Index: libmpdemux/demux_avs.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_avs.c,v
retrieving revision 1.3
diff -u -r1.3 demux_avs.c
--- libmpdemux/demux_avs.c	30 Apr 2005 09:05:45 -0000	1.3
+++ libmpdemux/demux_avs.c	23 May 2005 18:28:16 -0000
@@ -67,6 +67,9 @@
     AVS_Value handler;
     AVS_Clip *clip;
     const AVS_VideoInfo *video_info;
+#ifdef WIN32_LOADER
+    ldt_fs_t* ldt_fs;
+#endif
     HMODULE dll;
     int frameno;
     int init;
@@ -91,14 +94,14 @@
     memset(AVS, 0, sizeof(AVS_T));
 
 #ifdef WIN32_LOADER
-    Setup_LDT_Keeper();
+    AVS->ldt_fs = Setup_LDT_Keeper();
 #endif
     
     AVS->dll = LoadLibraryA("avisynth.dll");
     if(!AVS->dll)
     {
         mp_msg(MSGT_DEMUX ,MSGL_V, "AVS: failed to load avisynth.dll\n");
-        return NULL;
+        goto avs_err;
     }
     
     /* Dynamic import of needed stuff from avisynth.dll */
@@ -116,7 +119,7 @@
     if (!AVS->avs_env)
     {
         mp_msg(MSGT_DEMUX, MSGL_V, "AVS: avs_create_script_environment failed\n");
-        return NULL;
+        goto avs_err;
     }
     
 
@@ -125,16 +128,24 @@
     if (avs_is_error(AVS->handler))
     {
         mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Avisynth error: %s\n", avs_as_string(AVS->handler));
-        return NULL;
+        goto avs_err;
     }
 
     if (!avs_is_clip(AVS->handler))
     {
         mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Avisynth doesn't return a clip\n");
-        return NULL;
+        goto avs_err;
     }
     
     return AVS;
+
+avs_err:
+    if (AVS->dll) FreeLibrary(AVS->dll);
+#ifdef WIN32_LOADER
+    Restore_LDT_Keeper(AVS->ldt_fs);
+#endif
+    free(AVS);
+    return NULL;
 }
 
 /* Implement RGB MODES ?? */
@@ -354,6 +365,9 @@
             mp_msg(MSGT_DEMUX, MSGL_V, "AVS: Unloading avisynth.dll\n");
             FreeLibrary(AVS->dll);
         }
+#ifdef WIN32_LOADER
+        Restore_LDT_Keeper(AVS->ldt_fs);
+#endif
         free(AVS);
     }
 }


More information about the MPlayer-dev-eng mailing list