changeset 33739:9f6d46d325de

Remove gfree() from interface.c. Rename it nfree() and define it as macro.
author ib
date Thu, 07 Jul 2011 09:29:15 +0000
parents 998f94e62a61
children 2c02269701bd
files gui/interface.c gui/interface.h gui/skin/font.c gui/ui/actions.c gui/ui/gtk/equalizer.c gui/ui/gtk/fileselect.c gui/ui/gtk/playlist.c gui/ui/gtk/preferences.c gui/ui/main.c gui/ui/playbar.c gui/util/mem.h
diffstat 11 files changed, 74 insertions(+), 47 deletions(-) [+]
line wrap: on
line diff
--- a/gui/interface.c	Thu Jul 07 08:48:46 2011 +0000
+++ b/gui/interface.c	Thu Jul 07 09:29:15 2011 +0000
@@ -24,6 +24,7 @@
 #include "skin/skin.h"
 #include "ui/gmplayer.h"
 #include "ui/widgets.h"
+#include "util/mem.h"
 #include "util/string.h"
 #include "wm/ws.h"
 #include "wm/wsxdnd.h"
@@ -76,12 +77,6 @@
 
 static int initialized;
 
-void gfree(void **p)
-{
-    free(*p);
-    *p = NULL;
-}
-
 /**
  * \brief This actually creates a new list containing only one element...
  */
@@ -419,7 +414,7 @@
         vo_font   = read_font_desc(font_name, font_factor, 0);
 
         if (!vo_font) {
-            gfree((void **)&font_name);
+            nfree(font_name);
             font_name = gstrdup(MPLAYER_DATADIR "/font/font.desc");
             vo_font   = read_font_desc(font_name, font_factor, 0);
         }
@@ -793,7 +788,7 @@
         if (guiInfo.AudioFile)
             audio_stream = gstrdup(guiInfo.AudioFile);
         else if (guiInfo.FilenameChanged)
-            gfree((void **)&audio_stream);
+            nfree(audio_stream);
 
 // audio_stream = NULL;
 
@@ -961,8 +956,8 @@
             guiSetDF(guiInfo.Filename, next->path, next->name);
             guiInfo.StreamType      = STREAMTYPE_FILE;
             guiInfo.FilenameChanged = guiInfo.NewPlay = 1;
-            gfree((void **)&guiInfo.AudioFile);
-            gfree((void **)&guiInfo.Subtitlename);
+            nfree(guiInfo.AudioFile);
+            nfree(guiInfo.Subtitlename);
         } else {
             if (guiInfo.FilenameChanged || guiInfo.NewPlay)
                 break;
@@ -1221,7 +1216,7 @@
         return NULL;
 
     case gtkSetFontEncoding:
-        gfree((void **)&subtitle_font_encoding);
+        nfree(subtitle_font_encoding);
         subtitle_font_encoding = gstrdup((char *)vparam);
         guiLoadFont();
         return NULL;
@@ -1234,7 +1229,7 @@
 
 #ifdef CONFIG_ICONV
     case gtkSetSubEncoding:
-        gfree((void **)&sub_cp);
+        nfree(sub_cp);
         sub_cp = gstrdup((char *)vparam);
         break;
 #endif
@@ -1244,9 +1239,9 @@
     case gtkClearStruct:
 
         if ((unsigned int)vparam & guiFilenames) {
-            gfree((void **)&guiInfo.Filename);
-            gfree((void **)&guiInfo.Subtitlename);
-            gfree((void **)&guiInfo.AudioFile);
+            nfree(guiInfo.Filename);
+            nfree(guiInfo.Subtitlename);
+            nfree(guiInfo.AudioFile);
             gtkSet(gtkDelPl, 0, NULL);
         }
 
--- a/gui/interface.h	Thu Jul 07 08:48:46 2011 +0000
+++ b/gui/interface.h	Thu Jul 07 09:29:15 2011 +0000
@@ -225,7 +225,6 @@
 extern float gtkEquChannels[6][10];
 
 void gaddlist(char ***list, const char *entry);
-void gfree(void **p);
 void gmp_msg(int mod, int lev, const char *format, ...);
 void *gtkSet(int cmd, float fparam, void *vparam);
 void guiDone(void);
--- a/gui/skin/font.c	Thu Jul 07 08:48:46 2011 +0000
+++ b/gui/skin/font.c	Thu Jul 07 09:29:15 2011 +0000
@@ -22,8 +22,8 @@
 #include <string.h>
 
 #include "font.h"
-#include "gui/interface.h"
 #include "gui/util/cut.h"
+#include "gui/util/mem.h"
 #include "gui/util/string.h"
 #include "skin.h"
 
@@ -73,7 +73,7 @@
     for (i = 0; i < MAX_FONTS; i++) {
         if (Fonts[i]) {
             bpFree(&Fonts[i]->Bitmap);
-            gfree((void **)&Fonts[i]);
+            nfree(Fonts[i]);
         }
     }
 }
@@ -97,7 +97,7 @@
     f = fopen(buf, "rt");
 
     if (!f) {
-        gfree((void **)&Fonts[id]);
+        nfree(Fonts[id]);
         return -3;
     }
 
@@ -158,7 +158,7 @@
 
             if (skinBPRead(buf, &Fonts[id]->Bitmap) != 0) {
                 bpFree(&Fonts[id]->Bitmap);
-                gfree((void **)&Fonts[id]);
+                nfree(Fonts[id]);
                 fclose(f);
                 return -4;
             }
--- a/gui/ui/actions.c	Thu Jul 07 08:48:46 2011 +0000
+++ b/gui/ui/actions.c	Thu Jul 07 09:29:15 2011 +0000
@@ -25,6 +25,7 @@
 #include "gui/interface.h"
 #include "gui/skin/font.h"
 #include "gui/skin/skin.h"
+#include "gui/util/mem.h"
 #include "gui/util/string.h"
 #include "gui/wm/wsxdnd.h"
 #include "widgets.h"
@@ -261,8 +262,8 @@
         guiSetDF(guiInfo.Filename, dir, name)
 
     guiInfo.StreamType = type;
-    gfree((void **)&guiInfo.AudioFile);
-    gfree((void **)&guiInfo.Subtitlename);
+    nfree(guiInfo.AudioFile);
+    nfree(guiInfo.Subtitlename);
 }
 
 void uiCurr(void)
--- a/gui/ui/gtk/equalizer.c	Thu Jul 07 08:48:46 2011 +0000
+++ b/gui/ui/gtk/equalizer.c	Thu Jul 07 09:29:15 2011 +0000
@@ -39,6 +39,7 @@
 #include "libmpdemux/stheader.h"
 #include "libmpcodecs/dec_video.h"
 #include "gui/ui/widgets.h"
+#include "gui/util/mem.h"
 #include "gui/util/string.h"
 
 #include "equalizer.h"
@@ -562,12 +563,12 @@
 {
  if ( (int)user_data )
  { // if you pressed Ok
-  gfree( (void **)&gtkEquChannel1 ); gtkEquChannel1=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel1 ) ) );
-  gfree( (void **)&gtkEquChannel2 ); gtkEquChannel2=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel2 ) ) );
-  gfree( (void **)&gtkEquChannel3 ); gtkEquChannel3=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel3 ) ) );
-  gfree( (void **)&gtkEquChannel4 ); gtkEquChannel4=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel4 ) ) );
-  gfree( (void **)&gtkEquChannel5 ); gtkEquChannel5=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel5 ) ) );
-  gfree( (void **)&gtkEquChannel6 ); gtkEquChannel6=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel6 ) ) );
+  nfree( gtkEquChannel1 ); gtkEquChannel1=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel1 ) ) );
+  nfree( gtkEquChannel2 ); gtkEquChannel2=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel2 ) ) );
+  nfree( gtkEquChannel3 ); gtkEquChannel3=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel3 ) ) );
+  nfree( gtkEquChannel4 ); gtkEquChannel4=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel4 ) ) );
+  nfree( gtkEquChannel5 ); gtkEquChannel5=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel5 ) ) );
+  nfree( gtkEquChannel6 ); gtkEquChannel6=gstrdup( gtk_entry_get_text( GTK_ENTRY( CEChannel6 ) ) );
   eqSetChannelNames();
  }
  HideEquConfig();
--- a/gui/ui/gtk/fileselect.c	Thu Jul 07 08:48:46 2011 +0000
+++ b/gui/ui/gtk/fileselect.c	Thu Jul 07 09:29:15 2011 +0000
@@ -32,6 +32,7 @@
 
 #include "gui/app.h"
 #include "gui/interface.h"
+#include "gui/util/mem.h"
 #include "gui/util/string.h"
 #include "help_mp.h"
 #include "mpcommon.h"
@@ -371,7 +372,7 @@
     char * tmp = fsHistory[i]; fsHistory[i]=fsHistory[0]; fsHistory[0]=tmp;
     return;
    }
- gfree( (void **)&fsHistory[fsPersistant_MaxPos - 1] );
+ nfree( fsHistory[fsPersistant_MaxPos - 1] );
  for ( i=fsPersistant_MaxPos - 1;i;i-- ) fsHistory[i]=fsHistory[i - 1];
  fsHistory[0]=gstrdup( subject );
 }
@@ -480,8 +481,8 @@
           guiSetDF( guiInfo.Filename,fsSelectedDirectory,fsSelectedFile );
           guiInfo.StreamType=STREAMTYPE_FILE;
           guiInfo.FilenameChanged=1; sub_fps=0;
-	  gfree( (void **)&guiInfo.AudioFile );
-	  gfree( (void **)&guiInfo.Subtitlename );
+	  nfree( guiInfo.AudioFile );
+	  nfree( guiInfo.Subtitlename );
           fs_PersistantHistory( get_current_dir_name_utf8() );      //totem, write into history
           break;
    case fsSubtitleSelector:
--- a/gui/ui/gtk/playlist.c	Thu Jul 07 08:48:46 2011 +0000
+++ b/gui/ui/gtk/playlist.c	Thu Jul 07 09:29:15 2011 +0000
@@ -33,6 +33,7 @@
 
 #include "gui/interface.h"
 #include "gui/ui/widgets.h"
+#include "gui/util/mem.h"
 #include "playlist.h"
 #include "tools.h"
 
@@ -156,7 +157,7 @@
 {
  if ( !PlayList ) return;
  NrOfSelected=NrOfEntrys=0;
- gfree( (void **)&CLListSelected ); gfree( (void **)&CLFileSelected );
+ nfree( CLListSelected ); nfree( CLFileSelected );
  free( old_path );
  old_path=strdup( current_path );
  gtk_widget_hide( PlayList );
--- a/gui/ui/gtk/preferences.c	Thu Jul 07 08:48:46 2011 +0000
+++ b/gui/ui/gtk/preferences.c	Thu Jul 07 09:29:15 2011 +0000
@@ -44,6 +44,7 @@
 #include "gui/interface.h"
 #include "gui/ui/gmplayer.h"
 #include "gui/ui/widgets.h"
+#include "gui/util/mem.h"
 #include "gui/util/string.h"
 #include "preferences.h"
 #include "fileselect.h"
@@ -1563,33 +1564,33 @@
     case 1:
 #ifdef CONFIG_OSS_AUDIO
       if (strncmp(ao_driver[0], "oss", 3) == 0) {
-        gfree((void **) &gtkAOOSSDevice);
+        nfree(gtkAOOSSDevice);
         gtkAOOSSDevice = gstrdup(getGtkEntryText(CEAudioDevice));
-        gfree((void **) &gtkAOOSSMixer);
+        nfree(gtkAOOSSMixer);
         gtkAOOSSMixer = gstrdup(getGtkEntryText(CEAudioMixer));
-        gfree((void **) &gtkAOOSSMixerChannel);
+        nfree(gtkAOOSSMixerChannel);
         gtkAOOSSMixerChannel = gstrdup(getGtkEntryText(CEAudioMixerChannel));
       }
 #endif
 #ifdef CONFIG_ALSA
       if (strncmp(ao_driver[0], "alsa", 4) == 0) {
-        gfree((void **) &gtkAOALSADevice);
+        nfree(gtkAOALSADevice);
         gtkAOALSADevice = gstrdup(getGtkEntryText(CEAudioDevice));
-        gfree((void **) &gtkAOALSAMixer);
+        nfree(gtkAOALSAMixer);
         gtkAOALSAMixer = gstrdup(getGtkEntryText(CEAudioMixer));
-        gfree((void **) &gtkAOALSAMixerChannel);
+        nfree(gtkAOALSAMixerChannel);
         gtkAOALSAMixerChannel = gstrdup(getGtkEntryText(CEAudioMixerChannel));
       }
 #endif
 #ifdef CONFIG_SDL
       if (strncmp(ao_driver[0], "sdl", 3) == 0) {
-        gfree((void **) &gtkAOSDLDriver);
+        nfree(gtkAOSDLDriver);
         gtkAOSDLDriver = gstrdup(getGtkEntryText(CEAudioDevice));
       }
 #endif
 #ifdef CONFIG_ESD
       if (strncmp(ao_driver[0], "esd", 3) == 0) {
-        gfree((void **) &gtkAOESDDevice);
+        nfree(gtkAOESDDevice);
         gtkAOESDDevice = gstrdup(getGtkEntryText(CEAudioDevice));
       }
 #endif
@@ -1759,7 +1760,7 @@
  switch ( (int)user_data )
  {
   case 0: // Ok
-       gfree( (void **)&gtkDXR3Device ); gtkDXR3Device=strdup( gtk_entry_get_text( GTK_ENTRY( CEDXR3Device ) ) );
+       nfree( gtkDXR3Device ); gtkDXR3Device=strdup( gtk_entry_get_text( GTK_ENTRY( CEDXR3Device ) ) );
        gtkVfLAVC=gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( RBVLavc ) );
   case 1: // Cancel
        HideDXR3Config();
--- a/gui/ui/main.c	Thu Jul 07 08:48:46 2011 +0000
+++ b/gui/ui/main.c	Thu Jul 07 09:29:15 2011 +0000
@@ -30,6 +30,7 @@
 #include "gui/interface.h"
 #include "gui/skin/font.h"
 #include "gui/skin/skin.h"
+#include "gui/util/mem.h"
 #include "gui/util/string.h"
 #include "gui/wm/ws.h"
 
@@ -111,8 +112,8 @@
         break;
 
    case evPlayNetwork:
-        gfree( (void **)&guiInfo.Subtitlename );
-	gfree( (void **)&guiInfo.AudioFile );
+        nfree( guiInfo.Subtitlename );
+	nfree( guiInfo.AudioFile );
 	guiInfo.StreamType=STREAMTYPE_STREAM;
         goto play;
    case evSetURL:
@@ -243,7 +244,7 @@
         break;
    case evLoadSubtitle:  gtkShow( evLoadSubtitle,NULL );  break;
    case evDropSubtitle:
-	gfree( (void **)&guiInfo.Subtitlename );
+	nfree( guiInfo.Subtitlename );
 	guiLoadSubtitle( NULL );
 	break;
    case evLoadAudioFile: gtkShow( evLoadAudioFile,NULL ); break;
@@ -594,7 +595,7 @@
 	  if((len=strlen(++ext)) && (type=strstr(supported,ext)) &&\
 	     (type-supported)%4 == 0 && *(type+len) == '/'){
 	    /* handle subtitle file */
-	    gfree((void**)&subtitles);
+	    nfree(subtitles);
 	    subtitles = str;
 	    continue;
 	  }
@@ -632,7 +633,7 @@
     uiEventHandling( evPlay,0 );
   }
   if (subtitles) {
-    gfree((void**)&guiInfo.Subtitlename);
+    nfree(guiInfo.Subtitlename);
     guiInfo.Subtitlename = subtitles;
     guiLoadSubtitle(guiInfo.Subtitlename);
   }
--- a/gui/ui/playbar.c	Thu Jul 07 08:48:46 2011 +0000
+++ b/gui/ui/playbar.c	Thu Jul 07 09:29:15 2011 +0000
@@ -29,6 +29,7 @@
 #include "gui/interface.h"
 #include "gui/skin/font.h"
 #include "gui/skin/skin.h"
+#include "gui/util/mem.h"
 #include "gui/wm/ws.h"
 
 #include "help_mp.h"
@@ -243,7 +244,7 @@
 {
  if ( !guiApp.playbarIsPresent ) return;
 
- gfree( (void**)&playbarDrawBuffer );
+ nfree( playbarDrawBuffer );
 
  if ( ( playbarDrawBuffer = malloc( guiApp.playbar.Bitmap.ImageSize ) ) == NULL )
   {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gui/util/mem.h	Thu Jul 07 09:29:15 2011 +0000
@@ -0,0 +1,26 @@
+/*
+ * This file is part of MPlayer.
+ *
+ * MPlayer is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * MPlayer is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with MPlayer; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPLAYER_GUI_MEM_H
+#define MPLAYER_GUI_MEM_H
+
+#include <stdlib.h>
+
+#define nfree(p) do { free(p); p = NULL; } while (0)
+
+#endif /* MPLAYER_GUI_MEM_H */