/soc/2015/mmcc/main: 0f03341829bf: Passing NULL to free() or g_f...

Michael McConville mmcconville at mykolab.com
Thu Aug 13 17:10:02 EDT 2015


Changeset: 0f03341829bf16103361a2833984ecc737550797
Author:	 Michael McConville <mmcconville at mykolab.com>
Date:	 2015-08-13 17:09 -0400
Branch:	 default
URL: https://hg.pidgin.im/soc/2015/mmcc/main/rev/0f03341829bf

Description:

Passing NULL to free() or g_free() is safe (see POSIX, manuals)

diffstat:

 finch/gntaccount.c                             |   5 +-
 libpurple/ciphers/hmaccipher.c                 |  12 +--
 libpurple/http.c                               |   3 +-
 libpurple/network.c                            |  13 +--
 libpurple/plugins/filectl.c                    |  21 ------
 libpurple/plugins/ssl/ssl-nss.c                |   6 +-
 libpurple/protocols/jabber/chat.c              |   9 +-
 libpurple/protocols/jabber/disco.c             |   3 +-
 libpurple/protocols/jabber/google/jingleinfo.c |   3 +-
 libpurple/protocols/jabber/ibb.c               |   6 +-
 libpurple/protocols/jabber/jabber.c            |  12 +--
 libpurple/protocols/jabber/message.c           |   3 +-
 libpurple/protocols/jabber/presence.c          |  12 +--
 libpurple/protocols/jabber/si.c                |   3 +-
 libpurple/protocols/msn/object.c               |   3 +-
 libpurple/protocols/mxit/client.c              |  26 ++-----
 libpurple/protocols/mxit/formcmds.c            |   3 +-
 libpurple/protocols/mxit/markup.c              |   3 +-
 libpurple/protocols/mxit/multimx.c             |   6 +-
 libpurple/protocols/mxit/mxit.c                |  12 +--
 libpurple/protocols/mxit/roster.c              |  35 +++------
 libpurple/protocols/novell/nmconference.c      |   8 +-
 libpurple/protocols/novell/nmconn.c            |  10 +--
 libpurple/protocols/novell/nmcontact.c         |  33 ++------
 libpurple/protocols/novell/nmevent.c           |  53 ++++----------
 libpurple/protocols/novell/nmmessage.c         |   3 +-
 libpurple/protocols/novell/nmrequest.c         |   3 +-
 libpurple/protocols/novell/nmuser.c            |   4 +-
 libpurple/protocols/novell/nmuserrecord.c      |  90 +++++++------------------
 libpurple/protocols/novell/novell.c            |  30 ++------
 libpurple/protocols/oscar/family_locate.c      |  13 +--
 libpurple/protocols/sametime/sametime.c        |   4 +-
 libpurple/protocols/yahoo/yahoochat.c          |   9 +-
 libpurple/protocols/zephyr/ZAsyncLocate.c      |   4 +-
 libpurple/protocols/zephyr/Zinternal.c         |   3 -
 libpurple/protocols/zephyr/zephyr.c            |   6 +-
 libpurple/proxy.c                              |  18 +---
 37 files changed, 145 insertions(+), 345 deletions(-)

diffs (truncated from 1235 to 300 lines):

diff --git a/finch/gntaccount.c b/finch/gntaccount.c
--- a/finch/gntaccount.c
+++ b/finch/gntaccount.c
@@ -978,10 +978,7 @@ static void
 free_add_user_data(AddUserData *data)
 {
 	g_free(data->username);
-
-	if (data->alias != NULL)
-		g_free(data->alias);
-
+	g_free(data->alias);
 	g_free(data);
 }
 
diff --git a/libpurple/ciphers/hmaccipher.c b/libpurple/ciphers/hmaccipher.c
--- a/libpurple/ciphers/hmaccipher.c
+++ b/libpurple/ciphers/hmaccipher.c
@@ -77,14 +77,10 @@ purple_hmac_cipher_reset(PurpleCipher *c
 	if(PURPLE_IS_HASH(priv->hash))
 		purple_hash_reset(priv->hash);
 
-	if(priv->ipad) {
-		g_free(priv->ipad);
-		priv->ipad = NULL;
-	}
-	if(priv->opad) {
-		g_free(priv->opad);
-		priv->opad = NULL;
-	}
+	g_free(priv->ipad);
+	priv->ipad = NULL;
+	g_free(priv->opad);
+	priv->opad = NULL;
 }
 
 static void
diff --git a/libpurple/http.c b/libpurple/http.c
--- a/libpurple/http.c
+++ b/libpurple/http.c
@@ -751,8 +751,7 @@ static void _purple_http_gen_headers(Pur
 		request_url,
 		req->http11 ? "1.1" : "1.0");
 
-	if (tmp_url)
-		g_free(tmp_url);
+	g_free(tmp_url);
 
 	if (!purple_http_headers_get(hdrs, "host"))
 		g_string_append_printf(h, "Host: %s\r\n", url->host);
diff --git a/libpurple/network.c b/libpurple/network.c
--- a/libpurple/network.c
+++ b/libpurple/network.c
@@ -986,10 +986,9 @@ purple_network_set_stun_server(const gch
 			purple_debug_info("network",
 				"network is unavailable, don't try to update STUN IP");
 		}
-	} else if (stun_ip) {
-		g_free(stun_ip);
-		stun_ip = NULL;
 	}
+	g_free(stun_ip);
+	stun_ip = NULL;
 }
 
 void
@@ -1005,10 +1004,9 @@ purple_network_set_turn_server(const gch
 			purple_debug_info("network",
 				"network is unavailable, don't try to update TURN IP");
 		}
-	} else if (turn_ip) {
-		g_free(turn_ip);
-		turn_ip = NULL;
 	}
+	g_free(turn_ip);
+	turn_ip = NULL;
 }
 
 
@@ -1267,8 +1265,7 @@ purple_network_uninit(void)
 	purple_signal_unregister(purple_network_get_handle(),
 							 "network-configuration-changed");
 
-	if (stun_ip)
-		g_free(stun_ip);
+	g_free(stun_ip);
 
 	g_hash_table_destroy(upnp_port_mappings);
 	g_hash_table_destroy(nat_pmp_port_mappings);
diff --git a/libpurple/plugins/filectl.c b/libpurple/plugins/filectl.c
--- a/libpurple/plugins/filectl.c
+++ b/libpurple/plugins/filectl.c
@@ -86,27 +86,6 @@ run_commands()
 			free(arg1);
 			free(arg2);
 
-/* purple_find_conversation() is gone in 2.0.0. */
-#if 0
-		} else if (!g_ascii_strncasecmp(command, "send", 4)) {
-			PurpleConversation *conv;
-
-			arg1 = getarg(buffer, 1, 0);
-			arg2 = getarg(buffer, 2, 1);
-
-			conv = purple_find_conversation(PURPLE_CONV_TYPE_ANY, arg1);
-			if (conv != NULL)
-			{
-				/*
-				purple_conversation_write(conv, arg2, WFLAG_SEND, NULL, time(NULL), -1);
-				purple_serv_send_im(conv->gc, arg1, arg2, 0);
-				*/
-			}
-
-			free(arg1);
-			free(arg2);
-#endif
-
 		} else if (!g_ascii_strncasecmp(command, "away", 4)) {
 			arg1 = getarg(buffer, 1, 1);
 			/* serv_set_away_all(arg1); */
diff --git a/libpurple/plugins/ssl/ssl-nss.c b/libpurple/plugins/ssl/ssl-nss.c
--- a/libpurple/plugins/ssl/ssl-nss.c
+++ b/libpurple/plugins/ssl/ssl-nss.c
@@ -669,8 +669,7 @@ x509_import_from_file(const gchar *filen
 	if (len == 0) {
 		purple_debug_error("nss/x509",
 				"Certificate file has no contents!\n");
-		if (rawcert)
-			g_free(rawcert);
+		g_free(rawcert);
 		return NULL;
 	}
 
@@ -718,8 +717,7 @@ x509_importcerts_from_file(const gchar *
 	if (len == 0) {
 		purple_debug_error("nss/x509",
 				"Certificate file has no contents!\n");
-		if (rawcert)
-			g_free(rawcert);
+		g_free(rawcert);
 		return NULL;
 	}
 
diff --git a/libpurple/protocols/jabber/chat.c b/libpurple/protocols/jabber/chat.c
--- a/libpurple/protocols/jabber/chat.c
+++ b/libpurple/protocols/jabber/chat.c
@@ -540,8 +540,7 @@ static void jabber_chat_room_configure_c
 			_("Configuration error"), msg,
 			purple_request_cpar_from_connection(js->gc));
 
-		if(msg)
-			g_free(msg);
+		g_free(msg);
 		return;
 	}
 
@@ -621,8 +620,7 @@ jabber_chat_register_x_data_result_cb(Ja
 			_("Registration error"), msg,
 			purple_request_cpar_from_connection(js->gc));
 
-		if(msg)
-			g_free(msg);
+		g_free(msg);
 		return;
 	}
 }
@@ -692,8 +690,7 @@ static void jabber_chat_register_cb(Jabb
 			_("Registration error"), msg,
 			purple_request_cpar_from_connection(js->gc));
 
-		if(msg)
-			g_free(msg);
+		g_free(msg);
 		return;
 	}
 
diff --git a/libpurple/protocols/jabber/disco.c b/libpurple/protocols/jabber/disco.c
--- a/libpurple/protocols/jabber/disco.c
+++ b/libpurple/protocols/jabber/disco.c
@@ -452,8 +452,7 @@ jabber_disco_stun_lookup_cb(GSList *host
 			port = ntohs(addr.in.sin_port);
 		}
 
-		if (js->stun_ip)
-			g_free(js->stun_ip);
+		g_free(js->stun_ip);
 		js->stun_ip = g_strdup(dst);
 		js->stun_port = port;
 
diff --git a/libpurple/protocols/jabber/google/jingleinfo.c b/libpurple/protocols/jabber/google/jingleinfo.c
--- a/libpurple/protocols/jabber/google/jingleinfo.c
+++ b/libpurple/protocols/jabber/google/jingleinfo.c
@@ -53,8 +53,7 @@ jabber_google_stun_lookup_cb(GSList *hos
 			port = ntohs(addr.in.sin_port);
 		}
 
-		if (js->stun_ip)
-			g_free(js->stun_ip);
+		g_free(js->stun_ip);
 		js->stun_ip = g_strdup(dst);
 		js->stun_port = port;
 
diff --git a/libpurple/protocols/jabber/ibb.c b/libpurple/protocols/jabber/ibb.c
--- a/libpurple/protocols/jabber/ibb.c
+++ b/libpurple/protocols/jabber/ibb.c
@@ -294,10 +294,8 @@ jabber_ibb_session_send_acknowledge_cb(J
 
 	if (sess) {
 		/* reset callback */
-		if (sess->last_iq_id) {
-			g_free(sess->last_iq_id);
-			sess->last_iq_id = NULL;
-		}
+		g_free(sess->last_iq_id);
+		sess->last_iq_id = NULL;
 
 		if (type == JABBER_IQ_ERROR) {
 			jabber_ibb_session_close(sess);
diff --git a/libpurple/protocols/jabber/jabber.c b/libpurple/protocols/jabber/jabber.c
--- a/libpurple/protocols/jabber/jabber.c
+++ b/libpurple/protocols/jabber/jabber.c
@@ -103,10 +103,8 @@ static void jabber_stream_init(JabberStr
 {
 	char *open_stream;
 
-	if (js->stream_id) {
-		g_free(js->stream_id);
-		js->stream_id = NULL;
-	}
+	g_free(js->stream_id);
+	js->stream_id = NULL;
 
 	open_stream = g_strdup_printf("<stream:stream to='%s' "
 				          "xmlns='" NS_XMPP_CLIENT "' "
@@ -2651,10 +2649,8 @@ void jabber_convo_closed(PurpleConnectio
 
 	if((jb = jabber_buddy_find(js, who, TRUE)) &&
 			(jbr = jabber_buddy_find_resource(jb, jid->resource))) {
-		if(jbr->thread_id) {
-			g_free(jbr->thread_id);
-			jbr->thread_id = NULL;
-		}
+		g_free(jbr->thread_id);
+		jbr->thread_id = NULL;
 	}
 
 	jabber_id_free(jid);
diff --git a/libpurple/protocols/jabber/message.c b/libpurple/protocols/jabber/message.c
--- a/libpurple/protocols/jabber/message.c
+++ b/libpurple/protocols/jabber/message.c
@@ -147,8 +147,7 @@ static void handle_chat(JabberMessage *j
 					jbr->chat_states = JABBER_CHAT_STATES_UNSUPPORTED;
 			}
 
-			if(jbr->thread_id)
-				g_free(jbr->thread_id);
+			g_free(jbr->thread_id);
 			jbr->thread_id = g_strdup(jbr->thread_id);
 		}
 
diff --git a/libpurple/protocols/jabber/presence.c b/libpurple/protocols/jabber/presence.c
--- a/libpurple/protocols/jabber/presence.c
+++ b/libpurple/protocols/jabber/presence.c
@@ -245,10 +245,8 @@ void jabber_presence_send(JabberStream *
 
 		/* update old values */
 
-		if(js->old_msg)
-			g_free(js->old_msg);
-		if(js->old_avatarhash)
-			g_free(js->old_avatarhash);
+		g_free(js->old_msg);
+		g_free(js->old_avatarhash);
 		js->old_msg = g_strdup(stripped);
 		js->old_avatarhash = g_strdup(js->avatar_hash);
 		js->old_state = state;
@@ -945,10 +943,8 @@ void jabber_presence_parse(JabberStream 
 	if (presence.jid_from->node)
 		presence.chat = jabber_chat_find(js, presence.jid_from->node,
 		                                 presence.jid_from->domain);
-	if(presence.jb->error_msg) {
-		g_free(presence.jb->error_msg);
-		presence.jb->error_msg = NULL;
-	}
+	g_free(presence.jb->error_msg);
+	presence.jb->error_msg = NULL;
 
 	if (presence.type == JABBER_PRESENCE_AVAILABLE) {
 		presence.state = JABBER_BUDDY_STATE_ONLINE;
diff --git a/libpurple/protocols/jabber/si.c b/libpurple/protocols/jabber/si.c
--- a/libpurple/protocols/jabber/si.c
+++ b/libpurple/protocols/jabber/si.c
@@ -351,8 +351,7 @@ void jabber_bytestreams_parse(JabberStre
 	if(!jsx->accepted)
 		return;
 
-	if(jsx->iq_id)
-		g_free(jsx->iq_id);
+	g_free(jsx->iq_id);
 	jsx->iq_id = g_strdup(id);



More information about the Commits mailing list