[PATCH] Remove a bunch of useless if NULL before free

Clément Bœsch ubitux at gmail.com
Thu Nov 4 02:12:17 CET 2010


---
 asxparser.c               |   14 +++++++-------
 codec-cfg.c               |   18 ++++++------------
 command.c                 |    6 ++----
 m_config.c                |    8 ++++----
 m_option.c                |   11 +++++------
 mplayer.c                 |   10 ++++------
 playtree.c                |    6 +++---
 playtreeparser.c          |   24 ++++++++----------------
 stream/asf_streaming.c    |    6 +++---
 stream/audio_in.c         |    4 ++--
 stream/cdinfo.c           |    8 ++++----
 stream/http.c             |   19 +++++++++----------
 stream/network.c          |   16 ++++++----------
 stream/stream.c           |    4 ++--
 stream/stream_cddb.c      |    4 +---
 stream/stream_dvb.c       |   20 ++++++--------------
 stream/stream_ftp.c       |    2 +-
 stream/stream_netstream.c |    3 +--
 stream/stream_pvr.c       |   22 ++++++----------------
 stream/stream_radio.c     |    6 ++----
 stream/tv.c               |   12 +++++-------
 stream/tvi_dshow.c        |   20 +++++++-------------
 stream/tvi_v4l.c          |   24 ++++++++----------------
 stream/tvi_v4l2.c         |   15 +++++----------
 stream/url.c              |   18 +++++++++---------
 sub/font_load.c           |   12 ++++--------
 sub/font_load_ft.c        |   26 +++++++++++++-------------
 sub/spudec.c              |    6 ++----
 sub/sub_cc.c              |    7 +++++--
 sub/subreader.c           |    4 ++--
 sub/vobsub.c              |   18 ++++++------------
 subopt-helper.c           |    3 +--
 xvid_vbr.c                |    3 +--
 33 files changed, 150 insertions(+), 229 deletions(-)

diff --git a/asxparser.c b/asxparser.c
index 95ff7b9..9cdd306 100644
--- a/asxparser.c
+++ b/asxparser.c
@@ -87,7 +87,7 @@ asx_parser_new(void) {
 void
 asx_parser_free(ASX_Parser_t* parser) {
   if(!parser) return;
-  if(parser->ret_stack) free(parser->ret_stack);
+  free(parser->ret_stack);
   free(parser);
 
 }
@@ -289,7 +289,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
       if(*ptr3 == '\0') {
         mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing %s element body",parser->line,element);
         free(element);
-        if(attribs) free(attribs);
+        free(attribs);
         return -1;
       }
       if(ptr3[0] == '\n') parser->line++;
@@ -317,7 +317,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
       if(ptr4 == NULL || ptr4[1] == '\0') {
         mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing %s element body",parser->line,element);
         free(element);
-        if(attribs) free(attribs);
+        free(attribs);
         return -1;
       }
       if(ptr4[1] != '/' && strncasecmp(element,ptr4+1,strlen(element)) == 0) {
@@ -406,7 +406,7 @@ asx_parse_param(ASX_Parser_t* parser, char** attribs, play_tree_t* pt) {
   }
   play_tree_set_param(pt,name,val);
   free(name);
-  if(val) free(val);
+  free(val);
 }
 
 static void
@@ -498,7 +498,7 @@ asx_parse_entry(ASX_Parser_t* parser,char* buffer,char** _attribs) {
       nref++;
     } else
       mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element);
-    if(body) free(body);
+    free(body);
     asx_free_attribs(attribs);
   }
 
@@ -564,7 +564,7 @@ asx_parse_repeat(ASX_Parser_t* parser,char* buffer,char** _attribs) {
        asx_parse_param(parser,attribs,repeat);
      } else
        mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element);
-    if(body) free(body);
+     free(body);
      asx_free_attribs(attribs);
   }
 
@@ -649,7 +649,7 @@ asx_parser_build_tree(char* buffer,int deep) {
        }
      } else
        mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element);
-     if(body) free(body);
+     free(body);
      asx_free_attribs(attribs);
   }
 
diff --git a/codec-cfg.c b/codec-cfg.c
index 603f4ae..4db74c5 100644
--- a/codec-cfg.c
+++ b/codec-cfg.c
@@ -781,19 +781,13 @@ static void codecs_free(codecs_t* codecs,int count) {
     int i;
     for ( i = 0; i < count; i++)
         if ( codecs[i].name ) {
-            if( codecs[i].name )
-                free(codecs[i].name);
-            if( codecs[i].info )
-                free(codecs[i].info);
-            if( codecs[i].comment )
-                free(codecs[i].comment);
-            if( codecs[i].dll )
-                free(codecs[i].dll);
-            if( codecs[i].drv )
-                free(codecs[i].drv);
+            free(codecs[i].name);
+            free(codecs[i].info);
+            free(codecs[i].comment);
+            free(codecs[i].dll);
+            free(codecs[i].drv);
         }
-    if (codecs)
-        free(codecs);
+    free(codecs);
 }
 
 void codecs_uninit_free(void) {
diff --git a/command.c b/command.c
index 5dec22d..7c72056 100644
--- a/command.c
+++ b/command.c
@@ -512,8 +512,7 @@ static int mp_property_chapter(m_option_t *prop, int action, void *arg,
     else
         set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
                     MSGTR_OSDChapter, 0, MSGTR_Unknown);
-    if (chapter_name)
-        free(chapter_name);
+    free(chapter_name);
     return M_PROPERTY_OK;
 }
 
@@ -585,8 +584,7 @@ static int mp_property_angle(m_option_t *prop, int action, void *arg,
     angle = demuxer_set_angle(mpctx->demuxer, angle);
     set_osd_msg(OSD_MSG_TEXT, 1, osd_duration,
                         MSGTR_OSDAngle, angle, angles);
-    if (angle_name)
-        free(angle_name);
+    free(angle_name);
     return M_PROPERTY_OK;
 }
 
diff --git a/m_config.c b/m_config.c
index 9276393..dd2ea58 100644
--- a/m_config.c
+++ b/m_config.c
@@ -208,10 +208,10 @@ m_config_free(m_config_t* config) {
   for(p = config->profiles ; p ; p = pn) {
     pn = p->next;
     free(p->name);
-    if(p->desc) free(p->desc);
+    free(p->desc);
     for(j = 0 ; j < p->num_opts ; j++) {
       free(p->opts[2*j]);
-      if(p->opts[2*j+1]) free(p->opts[2*j+1]);
+      free(p->opts[2*j+1]);
     }
     free(p->opts);
     free(p);
@@ -459,7 +459,7 @@ m_config_parse_option(const m_config_t *config, char *arg, char *param, int set)
       free(lst[2*i]);
       free(lst[2*i+1]);
     }
-    if(lst) free(lst);
+    free(lst);
   } else
     r = m_option_parse(co->opt,arg,param,set ? co->slots->data : NULL,config->mode);
 
@@ -566,7 +566,7 @@ m_config_add_profile(m_config_t* config, char* name) {
 
 void
 m_profile_set_desc(m_profile_t* p, char* desc) {
-  if(p->desc) free(p->desc);
+  free(p->desc);
   p->desc = desc ? strdup(desc) : NULL;
 }
 
diff --git a/m_option.c b/m_option.c
index 8f7b458..a864078 100644
--- a/m_option.c
+++ b/m_option.c
@@ -400,8 +400,7 @@ static int parse_str(const m_option_t* opt,const char *name, const char *param,
   }
 
   if(dst) {
-    if(VAL(dst))
-      free(VAL(dst));
+    free(VAL(dst));
     VAL(dst) = strdup(param);
   }
 
@@ -416,7 +415,7 @@ static char* print_str(const m_option_t* opt,  const void* val) {
 static void copy_str(const m_option_t* opt,void* dst, const void* src) {
   if(dst && src) {
 #ifndef NO_FREE
-    if(VAL(dst)) free(VAL(dst)); //FIXME!!!
+    free(VAL(dst)); //FIXME!!!
 #endif
     VAL(dst) = VAL(src) ? strdup(VAL(src)) : NULL;
   }
@@ -531,7 +530,7 @@ static int str_list_del(char** del, int n,void* dst) {
   free(del);
 
   if(s == 0) {
-    if(lst) free(lst);
+    free(lst);
     VAL(dst) = NULL;
     return 1;
   }
@@ -544,7 +543,7 @@ static int str_list_del(char** del, int n,void* dst) {
   }
   d[s] = NULL;
 
-  if(lst) free(lst);
+  free(lst);
   VAL(dst) = d;
 
   return 1;
@@ -737,7 +736,7 @@ static void free_func_pf(void* src) {
   while(s) {
     n = s->next;
     free(s->name);
-    if(s->param) free(s->param);
+    free(s->param);
     free(s);
     s = n;
   }
diff --git a/mplayer.c b/mplayer.c
index 31758ed..e03bfe4 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -599,7 +599,7 @@ static void print_file_properties(const MPContext *mpctx, const char *filename)
 static void mp_dvdnav_context_free(MPContext *ctx){
     if (ctx->nav_smpi) free_mp_image(ctx->nav_smpi);
     ctx->nav_smpi = NULL;
-    if (ctx->nav_buffer) free(ctx->nav_buffer);
+    free(ctx->nav_buffer);
     ctx->nav_buffer = NULL;
     ctx->nav_start = NULL;
     ctx->nav_in_size = 0;
@@ -760,7 +760,7 @@ void exit_player_with_rc(enum exit_reason how, int rc)
   mpctx->playtree = NULL;
 
 
-  if(edl_records != NULL) free(edl_records); // free mem allocated for EDL
+  free(edl_records); // free mem allocated for EDL
   edl_records = NULL;
   switch(how) {
   case EXIT_QUIT:
@@ -2037,8 +2037,7 @@ static void mp_dvdnav_save_smpi(int in_size,
     if (mpctx->stream->type != STREAMTYPE_DVDNAV)
         return;
 
-    if (mpctx->nav_buffer)
-        free(mpctx->nav_buffer);
+    free(mpctx->nav_buffer);
 
     mpctx->nav_buffer = malloc(in_size);
     mpctx->nav_start = start;
@@ -3947,8 +3946,7 @@ if(step_sec>0) {
   while( !brk_cmd && (cmd = mp_input_get_cmd(0,0,0)) != NULL) {
       brk_cmd = run_command(mpctx, cmd);
       if (cmd->id == MP_CMD_EDL_LOADFILE) {
-          if (edl_filename)
-              free(edl_filename);
+          free(edl_filename);
           edl_filename = strdup(cmd->args[0].v.s);
           if (edl_filename)
               edl_loadfile();
diff --git a/playtree.c b/playtree.c
index 4276206..d9b29e8 100644
--- a/playtree.c
+++ b/playtree.c
@@ -68,7 +68,7 @@ play_tree_free(play_tree_t* pt, int children) {
   for(iter = pt->child ; iter != NULL ; iter = iter->next)
     iter->parent = NULL;
 
-  //if(pt->params) free(pt->params);
+  //free(pt->params);
   if(pt->files) {
     int i;
     for(i = 0 ; pt->files[i] != NULL ; i++)
@@ -384,8 +384,8 @@ play_tree_unset_param(play_tree_t* pt, char* name) {
   if(ni < 0)
     return 0;
 
-  if(pt->params[ni].name) free(pt->params[ni].name);
-  if(pt->params[ni].value) free(pt->params[ni].value);
+  free(pt->params[ni].name);
+  free(pt->params[ni].value);
 
   if(n > 1) {
     memmove(&pt->params[ni],&pt->params[ni+1],(n-ni)*sizeof(play_tree_param_t));
diff --git a/playtreeparser.c b/playtreeparser.c
index 6f76649..755920d 100644
--- a/playtreeparser.c
+++ b/playtreeparser.c
@@ -355,14 +355,9 @@ parse_pls(play_tree_parser_t* p) {
 	list = entry;
       last_entry = entry;
     }
-    if(entries[num].title) {
-      // When we have info in playtree we add this info
-      free(entries[num].title);
-    }
-    if(entries[num].length) {
-      // When we have info in playtree we add this info
-      free(entries[num].length);
-    }
+    // When we have info in playtree we add these info
+    free(entries[num].title);
+    free(entries[num].length);
   }
 
   free(entries);
@@ -518,10 +513,8 @@ parse_smil(play_tree_parser_t* p) {
   line = NULL;
   do {
     strstrip(src_line);
-    if (line) {
-      free(line);
-      line = NULL;
-    }
+    free(line);
+    line = NULL;
     /* If we're parsing smil over realrtsp and this is not the last packet and
      * this is the last line in the packet (terminating with ") ) we must get
      * the next line, strip the header, and concatenate it to the current line.
@@ -601,8 +594,7 @@ parse_smil(play_tree_parser_t* p) {
    }
   } while((src_line = play_tree_parser_get_line(p)) != NULL);
 
-  if (line)
-    free(line);
+  free(line);
 
   if(!list) return NULL; // Nothing found
 
@@ -810,8 +802,8 @@ play_tree_parser_free(play_tree_parser_t* p) {
   assert(p != NULL);
 #endif
 
-  if(p->buffer) free(p->buffer);
-  if(p->line) free(p->line);
+  free(p->buffer);
+  free(p->line);
   free(p);
 }
 
diff --git a/stream/asf_streaming.c b/stream/asf_streaming.c
index 3e5a13f..b100dbd 100644
--- a/stream/asf_streaming.c
+++ b/stream/asf_streaming.c
@@ -400,9 +400,9 @@ static int asf_streaming_parse_header(int fd, streaming_ctrl_t* streaming_ctrl)
 
 len_err_out:
   mp_msg(MSGT_NETWORK, MSGL_FATAL, MSGTR_MPDEMUX_ASF_InvalidLenInHeader);
-  if (buffer) free(buffer);
-  if (v_rates) free(v_rates);
-  if (a_rates) free(a_rates);
+  free(buffer);
+  free(v_rates);
+  free(a_rates);
   return -1;
 }
 
diff --git a/stream/audio_in.c b/stream/audio_in.c
index 48e3257..a05ccb1 100644
--- a/stream/audio_in.c
+++ b/stream/audio_in.c
@@ -133,7 +133,7 @@ int audio_in_set_device(audio_in_t *ai, char *device)
     switch (ai->type) {
 #ifdef CONFIG_ALSA
     case AUDIO_IN_ALSA:
-	if (ai->alsa.device) free(ai->alsa.device);
+	free(ai->alsa.device);
 	ai->alsa.device = strdup(device);
 	/* mplayer cannot handle colons in arguments */
 	for (i = 0; i < (int)strlen(ai->alsa.device); i++) {
@@ -143,7 +143,7 @@ int audio_in_set_device(audio_in_t *ai, char *device)
 #endif
 #ifdef CONFIG_OSS_AUDIO
     case AUDIO_IN_OSS:
-	if (ai->oss.device) free(ai->oss.device);
+	free(ai->oss.device);
 	ai->oss.device = strdup(device);
 	return 0;
 #endif
diff --git a/stream/cdinfo.c b/stream/cdinfo.c
index d70f550..c83405b 100644
--- a/stream/cdinfo.c
+++ b/stream/cdinfo.c
@@ -54,15 +54,15 @@ void
 cd_info_free(cd_info_t *cd_info) {
 	cd_track_t *cd_track, *cd_track_next;
 	if( cd_info==NULL ) return;
-	if( cd_info->artist!=NULL ) free(cd_info->artist);
-	if( cd_info->album!=NULL ) free(cd_info->album);
-	if( cd_info->genre!=NULL ) free(cd_info->genre);
+	free(cd_info->artist);
+	free(cd_info->album);
+	free(cd_info->genre);
 
 	cd_track_next = cd_info->first;
 	while( cd_track_next!=NULL ) {
 		cd_track = cd_track_next;
 		cd_track_next = cd_track->next;
-		if( cd_track->name!=NULL ) free(cd_track->name);
+		free(cd_track->name);
 		free(cd_track);
 	}
 }
diff --git a/stream/http.c b/stream/http.c
index 87dddc2..73e2cdf 100644
--- a/stream/http.c
+++ b/stream/http.c
@@ -307,17 +307,16 @@ void
 http_free( HTTP_header_t *http_hdr ) {
 	HTTP_field_t *field, *field2free;
 	if( http_hdr==NULL ) return;
-	if( http_hdr->protocol!=NULL ) free( http_hdr->protocol );
-	if( http_hdr->uri!=NULL ) free( http_hdr->uri );
-	if( http_hdr->reason_phrase!=NULL ) free( http_hdr->reason_phrase );
-	if( http_hdr->field_search!=NULL ) free( http_hdr->field_search );
-	if( http_hdr->method!=NULL ) free( http_hdr->method );
-	if( http_hdr->buffer!=NULL ) free( http_hdr->buffer );
+	free( http_hdr->protocol );
+	free( http_hdr->uri );
+	free( http_hdr->reason_phrase );
+	free( http_hdr->field_search );
+	free( http_hdr->method );
+	free( http_hdr->buffer );
 	field = http_hdr->first_field;
 	while( field!=NULL ) {
 		field2free = field;
-		if (field->field_name)
-		  free(field->field_name);
+		free(field->field_name);
 		field = field->next;
 		free( field2free );
 	}
@@ -440,7 +439,7 @@ http_response_parse( HTTP_header_t *http_hdr ) {
 		hdr_ptr = ptr+((*ptr=='\r')?2:1);
 	} while( hdr_ptr<(http_hdr->buffer+pos_hdr_sep) );
 
-	if( field!=NULL ) free( field );
+	free( field );
 
 	if( pos_hdr_sep+hdr_sep_len<http_hdr->buffer_size ) {
 		// Response has data!
@@ -513,7 +512,7 @@ http_build_request( HTTP_header_t *http_hdr ) {
 		memcpy( ptr, http_hdr->body, http_hdr->body_size );
 	}
 
-	if( uri ) free( uri );
+	free( uri );
 	return http_hdr->buffer;
 }
 
diff --git a/stream/network.c b/stream/network.c
index b065ece..99bffca 100644
--- a/stream/network.c
+++ b/stream/network.c
@@ -127,8 +127,8 @@ void
 streaming_ctrl_free( streaming_ctrl_t *streaming_ctrl ) {
 	if( streaming_ctrl==NULL ) return;
 	if( streaming_ctrl->url ) url_free( streaming_ctrl->url );
-	if( streaming_ctrl->buffer ) free( streaming_ctrl->buffer );
-	if( streaming_ctrl->data ) free( streaming_ctrl->data );
+	free( streaming_ctrl->buffer );
+	free( streaming_ctrl->data );
 	free( streaming_ctrl );
 }
 
@@ -331,14 +331,10 @@ http_authenticate(HTTP_header_t *http_hdr, URL_t *url, int *auth_retry) {
 		return -1;
 	}
 	if( *auth_retry>0 ) {
-		if( url->username ) {
-			free( url->username );
-			url->username = NULL;
-		}
-		if( url->password ) {
-			free( url->password );
-			url->password = NULL;
-		}
+		free( url->username );
+		url->username = NULL;
+		free( url->password );
+		url->password = NULL;
 	}
 
 	aut = http_get_field(http_hdr, "WWW-Authenticate");
diff --git a/stream/stream.c b/stream/stream.c
index 74537cf..a180818 100644
--- a/stream/stream.c
+++ b/stream/stream.c
@@ -513,8 +513,8 @@ void free_stream(stream_t *s){
 #endif
   // Disabled atm, i don't like that. s->priv can be anything after all
   // streams should destroy their priv on close
-  //if(s->priv) free(s->priv);
-  if(s->url) free(s->url);
+  //free(s->priv);
+  free(s->url);
   free(s);
 }
 
diff --git a/stream/stream_cddb.c b/stream/stream_cddb.c
index c8055ef..032f98a 100644
--- a/stream/stream_cddb.c
+++ b/stream/stream_cddb.c
@@ -792,9 +792,7 @@ static int cddb_retrieve(cddb_data_t *cddb_data)
     if (ret < 0)
         return -1;
 
-    if (cddb_data->cache_dir != NULL) {
-        free(cddb_data->cache_dir);
-    }
+    free(cddb_data->cache_dir);
     return 0;
 }
 
diff --git a/stream/stream_dvb.c b/stream/stream_dvb.c
index bd17a66..8ca6a81 100644
--- a/stream/stream_dvb.c
+++ b/stream/stream_dvb.c
@@ -403,8 +403,7 @@ static dvb_channels_list *dvb_get_channels(char *filename, int type)
 	fclose(f);
 	if(list->NUM_CHANNELS == 0)
 	{
-		if(list->channels != NULL)
-			free(list->channels);
+		free(list->channels);
 		free(list);
 		return NULL;
 	}
@@ -419,17 +418,13 @@ void dvb_free_config(dvb_config_t *config)
 
 	for(i=0; i<config->count; i++)
 	{
-		if(config->cards[i].name)
-			free(config->cards[i].name);
+		free(config->cards[i].name);
 		if(!config->cards[i].list)
 			continue;
 		if(config->cards[i].list->channels)
 		{
 			for(j=0; j<config->cards[i].list->NUM_CHANNELS; j++)
-			{
-				if(config->cards[i].list->channels[j].name)
-					free(config->cards[i].list->channels[j].name);
-			}
+				free(config->cards[i].list->channels[j].name);
 			free(config->cards[i].list->channels);
 		}
 		free(config->cards[i].list);
@@ -802,20 +797,17 @@ dvb_config_t *dvb_get_config(void)
 
 		if((access(conf_file, F_OK | R_OK) != 0))
 		{
-			if(conf_file)
-				free(conf_file);
+			free(conf_file);
 			conf_file = get_path("channels.conf");
 			if((access(conf_file, F_OK | R_OK) != 0))
 			{
-				if(conf_file)
-					free(conf_file);
+				free(conf_file);
 				conf_file = strdup(MPLAYER_CONFDIR "/channels.conf");
 			}
 		}
 
 		list = dvb_get_channels(conf_file, type);
-		if(conf_file)
-			free(conf_file);
+		free(conf_file);
 		if(list == NULL)
 			continue;
 
diff --git a/stream/stream_ftp.c b/stream/stream_ftp.c
index 0b28284..6e431a9 100644
--- a/stream/stream_ftp.c
+++ b/stream/stream_ftp.c
@@ -378,7 +378,7 @@ static void close_f(stream_t *s) {
   FtpSendCmd("QUIT",p,NULL);
 
   if(p->handle) closesocket(p->handle);
-  if(p->buf) free(p->buf);
+  free(p->buf);
 
   m_struct_free(&stream_opts,p);
 }
diff --git a/stream/stream_netstream.c b/stream/stream_netstream.c
index 47d1baa..52f2480 100644
--- a/stream/stream_netstream.c
+++ b/stream/stream_netstream.c
@@ -224,8 +224,7 @@ static void close_s(struct stream *s) {
   mp_net_stream_packet_t* pack;
 
   pack = send_net_stream_cmd(s,NET_STREAM_CLOSE,NULL,0);
-  if(pack)
-    free(pack);
+  free(pack);
 }
 
 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
diff --git a/stream/stream_pvr.c b/stream/stream_pvr.c
index 4c15246..d516ee9 100644
--- a/stream/stream_pvr.c
+++ b/stream/stream_pvr.c
@@ -188,15 +188,9 @@ pvr_uninit (struct pvr_t *pvr)
   if (pvr->dev_fd)
     close (pvr->dev_fd);
 
-  if (pvr->video_dev)
-    free (pvr->video_dev);
-
-  if (pvr->stationlist.list)
-    free (pvr->stationlist.list);
-
-  if (pvr->param_channel)
-    free (pvr->param_channel);
-
+  free (pvr->video_dev);
+  free (pvr->stationlist.list);
+  free (pvr->param_channel);
   free (pvr);
 }
 
@@ -215,11 +209,8 @@ copycreate_stationlist (stationlist_t *stationlist, int num)
 
   num = FFMAX (num, chanlists[chantab].count);
 
-  if (stationlist->list)
-  {
-    free (stationlist->list);
-    stationlist->list = NULL;
-  }
+  free (stationlist->list);
+  stationlist->list = NULL;
 
   stationlist->total = 0;
   stationlist->enabled = 0;
@@ -1151,8 +1142,7 @@ parse_v4l2_tv_options (struct pvr_t *pvr)
 
   if (stream_tv_defaults.device)
   {
-    if (pvr->video_dev)
-      free (pvr->video_dev);
+    free (pvr->video_dev);
     pvr->video_dev = strdup (stream_tv_defaults.device);
   }
 
diff --git a/stream/stream_radio.c b/stream/stream_radio.c
index dbdf290..c790397 100644
--- a/stream/stream_radio.c
+++ b/stream/stream_radio.c
@@ -1225,10 +1225,8 @@ static void close_s(struct stream *stream){
     if (!priv) return;
 
 #ifdef CONFIG_RADIO_CAPTURE
-    if(priv->audio_ringbuffer){
-        free(priv->audio_ringbuffer);
-        priv->audio_ringbuffer=NULL;
-    }
+    free(priv->audio_ringbuffer);
+    priv->audio_ringbuffer=NULL;
 
     priv->do_capture=0;
 #endif
diff --git a/stream/tv.c b/stream/tv.c
index d50802e..9cdc047 100644
--- a/stream/tv.c
+++ b/stream/tv.c
@@ -108,13 +108,11 @@ tvi_handle_t *tv_new_handle(int size, const tvi_functions_t *functions)
 
 void tv_free_handle(tvi_handle_t *h)
 {
-    if (h) {
-        if (h->priv)
-            free(h->priv);
-        if (h->scan)
-            free(h->scan);
-        free(h);
-    }
+    if (!h)
+        return;
+    free(h->priv);
+    free(h->scan);
+    free(h);
 }
 
 void tv_start_scan(tvi_handle_t *tvh, int start)
diff --git a/stream/tvi_dshow.c b/stream/tvi_dshow.c
index 8fcb7c2..4e6abb1 100644
--- a/stream/tvi_dshow.c
+++ b/stream/tvi_dshow.c
@@ -748,15 +748,12 @@ static void destroy_ringbuffer(grabber_ringbuffer_t * rb)
 
     if (rb->ringbuffer) {
 	for (i = 0; i < rb->buffersize; i++)
-	    if (rb->ringbuffer[i])
-		free(rb->ringbuffer[i]);
+	    free(rb->ringbuffer[i]);
 	free(rb->ringbuffer);
 	rb->ringbuffer = NULL;
     }
-    if (rb->dpts) {
-	free(rb->dpts);
-	rb->dpts = NULL;
-    }
+    free(rb->dpts);
+    rb->dpts = NULL;
     if (rb->pMutex) {
 	DeleteCriticalSection(rb->pMutex);
 	free(rb->pMutex);
@@ -2091,15 +2088,13 @@ static HRESULT get_available_formats_stream(chain_t *chain)
     }
     if (!done) {
 	for (i = 0; i < count; i++) {
-	    if (pBuf && pBuf[i])
+	    if (pBuf)
 		free(pBuf[i]);
 	    if (arpmt && arpmt[i])
 		DeleteMediaType(arpmt[i]);
 	}
-	if (pBuf)
-	    free(pBuf);
-	if (arpmt)
-	    free(arpmt);
+	free(pBuf);
+	free(arpmt);
 	if (hr != S_OK) {
 	    mp_msg(MSGT_TV, MSGL_DBG4, "tvi_dshow: Call to GetStreamCaps failed (get_available_formats_stream)\n");
 	    return hr;
@@ -2221,8 +2216,7 @@ static HRESULT get_available_formats_pin(ICaptureGraphBuilder2 * pBuilder,
 	for (i = 0; i < count; i++) {
 	    if (arpmt[i])
 		DeleteMediaType(arpmt[i]);
-	    if (pBuf[i])
-		free(pBuf[i]);
+	    free(pBuf[i]);
 	}
 	free(arpmt);
 	free(pBuf);
diff --git a/stream/tvi_v4l.c b/stream/tvi_v4l.c
index d380a36..bbf290e 100644
--- a/stream/tvi_v4l.c
+++ b/stream/tvi_v4l.c
@@ -676,10 +676,8 @@ static int init(priv_t *priv)
     return 1;
 
 malloc_failed:
-    if (priv->channels)
-        free(priv->channels);
-    if (priv->buf)
-        free(priv->buf);
+    free(priv->channels);
+    free(priv->buf);
 err:
     if (priv->video_fd != -1)
         close(priv->video_fd);
@@ -702,10 +700,8 @@ static int uninit(priv_t *priv)
         priv->vbi_fd=0;
     }
 
-    if(priv->vbi_dev){
-        free(priv->vbi_dev);
-        priv->vbi_dev=0;
-    }
+    free(priv->vbi_dev);
+    priv->vbi_dev = NULL;
 
     priv->shutdown = 1;
 
@@ -752,15 +748,11 @@ static int uninit(priv_t *priv)
         free(priv->video_ringbuffer);
     }
 
-    if (priv->video_timebuffer)
-        free(priv->video_timebuffer);
-    if (priv->video_avg_buffer)
-        free(priv->video_avg_buffer);
+    free(priv->video_timebuffer);
+    free(priv->video_avg_buffer);
     if (!priv->tv_param->noaudio) {
-        if (priv->audio_ringbuffer)
-            free(priv->audio_ringbuffer);
-        if (priv->audio_skew_buffer)
-            free(priv->audio_skew_buffer);
+        free(priv->audio_ringbuffer);
+        free(priv->audio_skew_buffer);
     }
 
     return 1;
diff --git a/stream/tvi_v4l2.c b/stream/tvi_v4l2.c
index f5cc9d0..90cb1a6 100644
--- a/stream/tvi_v4l2.c
+++ b/stream/tvi_v4l2.c
@@ -1112,10 +1112,8 @@ static int uninit(priv_t *priv)
         priv->vbi_fd=0;
     }
 
-    if(priv->vbi_dev){
-        free(priv->vbi_dev);
-	priv->vbi_dev=0;
-    }
+    free(priv->vbi_dev);
+    priv->vbi_dev = NULL;
     priv->shutdown = 1;
     if(priv->video_grabber_thread)
         pthread_join(priv->video_grabber_thread, NULL);
@@ -1173,12 +1171,9 @@ static int uninit(priv_t *priv)
         free(priv->video_ringbuffer);
     }
     if (!priv->tv_param->noaudio) {
-        if (priv->audio_ringbuffer)
-            free(priv->audio_ringbuffer);
-        if (priv->audio_skew_buffer)
-            free(priv->audio_skew_buffer);
-        if (priv->audio_skew_delta_buffer)
-            free(priv->audio_skew_delta_buffer);
+        free(priv->audio_ringbuffer);
+        free(priv->audio_skew_buffer);
+        free(priv->audio_skew_delta_buffer);
 
         audio_in_uninit(&priv->audio_in);
     }
diff --git a/stream/url.c b/stream/url.c
index 62e3bdc..a32287f 100644
--- a/stream/url.c
+++ b/stream/url.c
@@ -233,7 +233,7 @@ url_new(const char* url) {
         free(escfilename);
 	return Curl;
 err_out:
-	if (escfilename) free(escfilename);
+	free(escfilename);
 	if (Curl) url_free(Curl);
 	return NULL;
 }
@@ -241,12 +241,12 @@ err_out:
 void
 url_free(URL_t* url) {
 	if(!url) return;
-	if(url->url) free(url->url);
-	if(url->protocol) free(url->protocol);
-	if(url->hostname) free(url->hostname);
-	if(url->file) free(url->file);
-	if(url->username) free(url->username);
-	if(url->password) free(url->password);
+	free(url->url);
+	free(url->protocol);
+	free(url->hostname);
+	free(url->file);
+	free(url->username);
+	free(url->password);
 	free(url);
 }
 
@@ -379,8 +379,8 @@ url_escape_string(char *outbuf, const char *inbuf) {
 		i += strlen(in);
 	}
 	*outbuf = '\0';
-	if(tmp) free(tmp);
-	if(unesc) free(unesc);
+	free(tmp);
+	free(unesc);
 }
 
 #ifdef URL_DEBUG
diff --git a/sub/font_load.c b/sub/font_load.c
index 15bc306..4d22a4d 100644
--- a/sub/font_load.c
+++ b/sub/font_load.c
@@ -168,8 +168,7 @@ while(fgets(sor,1020,f)){
 
   if(strcmp(section,"[fpath]")==0){
       if(pdb==1){
-	  if (desc->fpath)
-	     free (desc->fpath); // release previously allocated memory
+          free (desc->fpath); // release previously allocated memory
           desc->fpath=strdup(p[0]);
           continue;
       }
@@ -344,12 +343,9 @@ return desc;
 fail_out:
   if (f)
     fclose(f);
-  if (desc->fpath)
-    free(desc->fpath);
-  if (desc->name)
-    free(desc->name);
-  if (desc)
-    free(desc);
+  free(desc->fpath);
+  free(desc->name);
+  free(desc);
   return NULL;
 }
 
diff --git a/sub/font_load_ft.c b/sub/font_load_ft.c
index 7a1705b..b0dc996 100644
--- a/sub/font_load_ft.c
+++ b/sub/font_load_ft.c
@@ -860,27 +860,27 @@ void free_font_desc(font_desc_t *desc)
 
 //    if (!desc->dynamic) return; // some vo_aa crap, better leaking than crashing
 
-    if (desc->name) free(desc->name);
-    if (desc->fpath) free(desc->fpath);
+    free(desc->name);
+    free(desc->fpath);
 
     for(i = 0; i < 16; i++) {
 	if (desc->pic_a[i]) {
-	    if (desc->pic_a[i]->bmp) free(desc->pic_a[i]->bmp);
-	    if (desc->pic_a[i]->pal) free(desc->pic_a[i]->pal);
-	    free (desc->pic_a[i]);
+	    free(desc->pic_a[i]->bmp);
+	    free(desc->pic_a[i]->pal);
+	    free(desc->pic_a[i]);
 	}
 	if (desc->pic_b[i]) {
-	    if (desc->pic_b[i]->bmp) free(desc->pic_b[i]->bmp);
-	    if (desc->pic_b[i]->pal) free(desc->pic_b[i]->pal);
-	    free (desc->pic_b[i]);
+	    free(desc->pic_b[i]->bmp);
+	    free(desc->pic_b[i]->pal);
+	    free(desc->pic_b[i]);
 	}
     }
 
-    if (desc->tables.g) free(desc->tables.g);
-    if (desc->tables.gt2) free(desc->tables.gt2);
-    if (desc->tables.om) free(desc->tables.om);
-    if (desc->tables.omt) free(desc->tables.omt);
-    if (desc->tables.tmp) free(desc->tables.tmp);
+    free(desc->tables.g);
+    free(desc->tables.gt2);
+    free(desc->tables.om);
+    free(desc->tables.omt);
+    free(desc->tables.tmp);
 
     for(i = 0; i < desc->face_cnt; i++) {
 	FT_Done_Face(desc->faces[i]);
diff --git a/sub/spudec.c b/sub/spudec.c
index e7ccf0e..b46733b 100644
--- a/sub/spudec.c
+++ b/sub/spudec.c
@@ -146,8 +146,7 @@ static packet_t *spudec_dequeue_packet(spudec_handle_t *this)
 
 static void spudec_free_packet(packet_t *packet)
 {
-  if (packet->packet != NULL)
-    free(packet->packet);
+  free(packet->packet);
   free(packet);
 }
 
@@ -609,8 +608,7 @@ void spudec_assemble(void *this, unsigned char *packet, unsigned int len, int pt
     unsigned int len2 = get_be16(packet);
     // Start new fragment
     if (spu->packet_reserve < len2) {
-      if (spu->packet != NULL)
-	free(spu->packet);
+      free(spu->packet);
       spu->packet = malloc(len2);
       spu->packet_reserve = spu->packet != NULL ? len2 : 0;
     }
diff --git a/sub/sub_cc.c b/sub/sub_cc.c
index 260d63b..78d7339 100644
--- a/sub/sub_cc.c
+++ b/sub/sub_cc.c
@@ -81,7 +81,10 @@ static void clear_buffer(subtitle *buf)
 {
 	int i;
 	buf->lines=0;
-	for(i=0;i<SUB_MAX_TEXT;i++) if(buf->text[i]) {free(buf->text[i]);buf->text[i]=NULL;}
+	for(i=0;i<SUB_MAX_TEXT;i++) {
+		free(buf->text[i]);
+		buf->text[i]=NULL;
+	}
 }
 
 
@@ -95,7 +98,7 @@ static void scroll_buffer(subtitle* buf)
 
 	while(buf->lines > cc_lines)
 	{
-		if(buf->text[0]) free(buf->text[0]);
+		free(buf->text[0]);
 
 		for(i = 0; i < (buf->lines - 1); i++) buf->text[i] = buf->text[i+1];
 
diff --git a/sub/subreader.c b/sub/subreader.c
index f04140c..42d523b 100644
--- a/sub/subreader.c
+++ b/sub/subreader.c
@@ -1513,7 +1513,7 @@ sub_data* sub_read_file (char *filename, float fps) {
 #ifdef CONFIG_ICONV
           subcp_close();
 #endif
-    	  if ( first ) free(first);
+	  free(first);
 	  free(alloced_sub);
 	  return NULL;
 	 }
@@ -2043,7 +2043,7 @@ char** sub_filenames(const char* path, char *fname)
 
     }
 
-    if (tmp_sub_id) free(tmp_sub_id);
+    free(tmp_sub_id);
 
     free(f_dir);
     free(f_fname);
diff --git a/sub/vobsub.c b/sub/vobsub.c
index c3f7d56..9416adb 100644
--- a/sub/vobsub.c
+++ b/sub/vobsub.c
@@ -311,8 +311,7 @@ static mpeg_t *mpeg_open(const char *filename)
 
 static void mpeg_free(mpeg_t *mpeg)
 {
-    if (mpeg->packet)
-        free(mpeg->packet);
+    free(mpeg->packet);
     if (mpeg->stream)
         rar_close(mpeg->stream);
     free(mpeg);
@@ -433,8 +432,7 @@ static int mpeg_run(mpeg_t *mpeg)
             }
             mpeg->packet_size = len - ((unsigned int) mpeg_tell(mpeg) - idx);
             if (mpeg->packet_reserve < mpeg->packet_size) {
-                if (mpeg->packet)
-                    free(mpeg->packet);
+                free(mpeg->packet);
                 mpeg->packet = malloc(mpeg->packet_size);
                 if (mpeg->packet)
                     mpeg->packet_reserve = mpeg->packet_size;
@@ -507,8 +505,7 @@ static void packet_construct(packet_t *pkt)
 
 static void packet_destroy(packet_t *pkt)
 {
-    if (pkt->data)
-        free(pkt->data);
+    free(pkt->data);
 }
 
 static void packet_queue_construct(packet_queue_t *queue)
@@ -634,8 +631,7 @@ static int vobsub_add_id(vobsub_t *vob, const char *id, size_t idlen,
     if (vobsub_ensure_spu_stream(vob, index) < 0)
         return -1;
     if (id && idlen) {
-        if (vob->spu_streams[index].id)
-            free(vob->spu_streams[index].id);
+        free(vob->spu_streams[index].id);
         vob->spu_streams[index].id = malloc(idlen + 1);
         if (vob->spu_streams[index].id == NULL) {
             mp_msg(MSGT_VOBSUB, MSGL_FATAL, "vobsub_add_id: malloc failure");
@@ -866,8 +862,7 @@ static int vobsub_parse_one_line(vobsub_t *vob, rar_stream_t *fd,
             mp_msg(MSGT_VOBSUB, MSGL_ERR,  "ERROR in %s", line);
         break;
     } while (1);
-    if (line)
-      free(line);
+    free(line);
     return res;
 }
 
@@ -983,8 +978,7 @@ void *vobsub_open(const char *const name, const char *const ifo,
             }
             if (spu)
                 *spu = spudec_new_scaled(vob->palette, vob->orig_frame_width, vob->orig_frame_height, extradata, extradata_len);
-            if (extradata)
-                free(extradata);
+            free(extradata);
 
             /* read the indexed mpeg_stream */
             strcpy(buf, name);
diff --git a/subopt-helper.c b/subopt-helper.c
index 37c634b..5a2f19e 100644
--- a/subopt-helper.c
+++ b/subopt-helper.c
@@ -226,8 +226,7 @@ int subopt_parse( char const * const str, const opt_t * opts )
                   tmp.str = NULL;
                   tmp.len = 0;
                   last = parse_str( &str[parse_pos], &tmp );
-                  if (*valp)
-                    free(*valp);
+                  free(*valp);
                   *valp = NULL;
                   if (tmp.str && tmp.len > 0) {
                     *valp = malloc(tmp.len + 1);
diff --git a/xvid_vbr.c b/xvid_vbr.c
index 0805324..45e0024 100644
--- a/xvid_vbr.c
+++ b/xvid_vbr.c
@@ -1580,8 +1580,7 @@ static int vbr_finish_2pass2(void *sstate)
 		return(-1);
 
 	/* Free the memory */
-	if(state->keyframe_locations)
-		free(state->keyframe_locations);
+	free(state->keyframe_locations);
 
 	return(0);
 
-- 
1.7.3.2


--nFreZHaLTZJo0R7j--


More information about the MPlayer-dev-eng mailing list