From 3c1dec8f3b4c14a81faeebf2ca4bd2edea5847e0 Mon Sep 17 00:00:00 2001 From: Stefan Becker Date: Tue, 9 Feb 2010 16:11:05 +0200 Subject: [PATCH] Coverity: fix various warnings Code checked with Coverity Prevent 4.5.0 - all checkers enabled - user models: glib memory allocation - derived models: Fedora 12 builds of glib2-2.22.4 & pidgin-2.6.5 RPMs Warnings fixed: - BAD_FREE - DEAD_CODE - FORWARD_NULL - PW.PARAMETER_HIDDEN - SECURE_CODING - REVERSE_INULL - USE_AFTER_FREE --- src/core/sipe-dialog.c | 35 ++++++++++++++++++++--------------- src/core/sipe.c | 48 +++++++++++++++++++++++++----------------------- src/core/sipmsg.c | 8 ++++---- 3 files changed, 49 insertions(+), 42 deletions(-) diff --git a/src/core/sipe-dialog.c b/src/core/sipe-dialog.c index 70355eee..cd71d023 100644 --- a/src/core/sipe-dialog.c +++ b/src/core/sipe-dialog.c @@ -33,6 +33,7 @@ void sipe_dialog_free(struct sip_dialog *dialog) { GSList *entry; + void *data; if (!dialog) return; @@ -40,13 +41,15 @@ void sipe_dialog_free(struct sip_dialog *dialog) g_free(dialog->endpoint_GUID); entry = dialog->routes; while (entry) { - g_free(entry->data); - entry = g_slist_remove(entry, entry->data); + data = entry->data; + entry = g_slist_remove(entry, data); + g_free(data); } entry = dialog->supported; while (entry) { - g_free(entry->data); - entry = g_slist_remove(entry, entry->data); + data = entry->data; + entry = g_slist_remove(entry, data); + g_free(data); } g_free(dialog->callid); @@ -63,7 +66,8 @@ void sipe_subscription_free(struct sip_subscription *subscription) if (!subscription) return; g_free(subscription->event); - sipe_dialog_free(&subscription->dialog); + /* NOTE: use cast to prevent BAD_FREE warning from Coverity */ + sipe_dialog_free((struct sip_dialog *) subscription); } struct sip_dialog *sipe_dialog_add(struct sip_session *session) @@ -82,16 +86,16 @@ sipe_dialog_find_3(struct sip_session *session, if ( dialog_in->callid && dialog_in->ourtag && dialog_in->theirtag && - + dialog->callid && dialog->ourtag && - dialog->theirtag && - + dialog->theirtag && + !g_ascii_strcasecmp(dialog_in->callid, dialog->callid) && !g_ascii_strcasecmp(dialog_in->ourtag, dialog->ourtag) && - !g_ascii_strcasecmp(dialog_in->theirtag, dialog->theirtag)) + !g_ascii_strcasecmp(dialog_in->theirtag, dialog->theirtag)) { - purple_debug_info("sipe", "sipe_dialog_find_3 who='%s'\n", + purple_debug_info("sipe", "sipe_dialog_find_3 who='%s'\n", dialog->with ? dialog->with : ""); return dialog; } @@ -141,8 +145,9 @@ void sipe_dialog_remove_all(struct sip_session *session) { GSList *entry = session->dialogs; while (entry) { - sipe_dialog_free(entry->data); - entry = g_slist_remove(entry, entry->data); + struct sip_dialog *dialog = entry->data; + entry = g_slist_remove(entry, dialog); + sipe_dialog_free(dialog); } } @@ -177,7 +182,7 @@ static void sipe_get_route_header(const struct sipmsg *msg, if (contact) { dialog->request = contact; } - + /* logic for strict router only - RFC3261 - 12.2.1.1 */ /* @TODO: proper check for presence of 'lr' PARAMETER in URI */ if (dialog->routes && !strstr(dialog->routes->data, ";lr")) { @@ -185,7 +190,7 @@ static void sipe_get_route_header(const struct sipmsg *msg, dialog->routes = g_slist_remove(dialog->routes, dialog->routes->data); if (contact) { dialog->routes = g_slist_append(dialog->routes, contact); - } + } } } @@ -243,7 +248,7 @@ void sipe_dialog_parse(struct sip_dialog *dialog, if (dialog->theirepid && strstr(dialog->theirepid, "tag=")) { dialog->theirepid = strtok(dialog->theirepid, ";"); } - + if ((session_expires_header = sipmsg_find_header(msg, "Session-Expires"))) { dialog->expires = atoi(session_expires_header); } diff --git a/src/core/sipe.c b/src/core/sipe.c index 69a571c9..d2973eb1 100644 --- a/src/core/sipe.c +++ b/src/core/sipe.c @@ -827,9 +827,9 @@ void send_sip_response(PurpleConnection *gc, struct sipmsg *msg, int code, } if (body) { - gchar len[12]; - sprintf(len, "%" G_GSIZE_FORMAT , (gsize) strlen(body)); + gchar *len = g_strdup_printf("%" G_GSIZE_FORMAT , (gsize) strlen(body)); sipmsg_add_header(msg, "Content-Length", len); + g_free(len); } else { sipmsg_add_header(msg, "Content-Length", "0"); } @@ -1578,7 +1578,7 @@ sipe_apply_calendar_status(struct sipe_account_data *sip, g_free(sbuddy->activity); sbuddy->activity = g_strdup(sbuddy->last_non_cal_activity); } - + if (!status_id) { purple_debug_info("sipe", "sipe_apply_calendar_status: status_id is NULL for %s, exiting.\n", sbuddy->name ? sbuddy->name : "" ); @@ -1611,12 +1611,12 @@ sipe_apply_calendar_status(struct sipe_account_data *sip, } /* then set status_id actually */ - purple_debug_info("sipe", "sipe_apply_calendar_status: to %s for %s\n", status_id ? status_id : "", sbuddy->name ? sbuddy->name : "" ); + purple_debug_info("sipe", "sipe_apply_calendar_status: to %s for %s\n", status_id, sbuddy->name ? sbuddy->name : "" ); purple_prpl_got_user_status(sip->account, sbuddy->name, status_id, NULL); /* set our account state to the one in roaming (including calendar info) */ self_uri = sip_uri_self(sip); - if (sip->initial_state_published && !strcmp(sbuddy->name, self_uri)) { + if (sip->initial_state_published && sbuddy->name && !strcmp(sbuddy->name, self_uri)) { if (!strcmp(status_id, SIPE_STATUS_ID_OFFLINE)) { status_id = g_strdup(SIPE_STATUS_ID_INVISIBLE); /* not not let offline status switch us off */ } @@ -2752,8 +2752,9 @@ free_container(struct sipe_container *container) entry = container->members; while (entry) { - g_free(entry->data); - entry = g_slist_remove(entry, entry->data); + void *data = entry->data; + entry = g_slist_remove(entry, data); + g_free(data); } g_free(container); } @@ -3085,9 +3086,8 @@ sipe_get_first_last_names(struct sipe_account_data *sip, g_free(tmp); } - has_comma = (strstr(display_name, ",") != NULL); - if (display_name) { + has_comma = (strstr(display_name, ",") != NULL); display_name = purple_strreplace((tmp = display_name), ", ", " "); g_free(tmp); display_name = purple_strreplace((tmp = display_name), ",", " "); @@ -3259,7 +3259,7 @@ sipe_set_purple_account_status_and_note(const PurpleAccount *account, { changed = FALSE; } - + if (purple_savedstatus_is_idleaway()) { changed = FALSE; } @@ -4339,10 +4339,11 @@ sipe_invite(struct sipe_account_data *sip, msgr_value = sipmsg_get_msgr_string(msgformat); g_free(msgformat); - msgr = ""; if (msgr_value) { msgr = g_strdup_printf(";msgr=%s", msgr_value); g_free(msgr_value); + } else { + msgr = g_strdup(""); } base64_msg = purple_base64_encode((guchar*) msgtext, strlen(msgtext)); @@ -4885,10 +4886,10 @@ static void process_incoming_message(struct sipe_account_data *sip, struct sipms session = sipe_session_find_im(sip, from); } if (session) { - gchar *msg = g_strdup_printf(_("Received a message with unrecognized contents from %s"), - from); - sipe_present_err(sip, session, msg); - g_free(msg); + gchar *errmsg = g_strdup_printf(_("Received a message with unrecognized contents from %s"), + from); + sipe_present_err(sip, session, errmsg); + g_free(errmsg); } purple_debug_info("sipe", "got unknown mime-type '%s'\n", contenttype); @@ -5217,7 +5218,7 @@ gboolean process_register_response(struct sipe_account_data *sip, struct sipmsg tmp = sipmsg_find_auth_header(msg, auth_scheme); if (tmp) { - purple_debug(PURPLE_DEBUG_MISC, "sipe", "process_register_response - Auth header: %s\n", tmp ? tmp : ""); + purple_debug(PURPLE_DEBUG_MISC, "sipe", "process_register_response - Auth header: %s\n", tmp); fill_auth(tmp, &sip->registrar); } @@ -5842,7 +5843,7 @@ static void process_incoming_notify_rlmi(struct sipe_account_data *sip, const gc /* state */ else if(!strcmp(attrVar, "state")) { - char *data; + char *tmp; int availability; xmlnode *xn_availability; xmlnode *xn_activity; @@ -5858,9 +5859,9 @@ static void process_incoming_notify_rlmi(struct sipe_account_data *sip, const gc xn_meeting_subject = xmlnode_get_child(xn_node, "meetingSubject"); xn_meeting_location = xmlnode_get_child(xn_node, "meetingLocation"); - data = xmlnode_get_data(xn_availability); - availability = atoi(data); - g_free(data); + tmp = xmlnode_get_data(xn_availability); + availability = atoi(tmp); + g_free(tmp); /* activity, meeting_subject, meeting_location */ if (sbuddy) { @@ -8062,9 +8063,10 @@ static void sipe_udp_host_resolved(GSList *hosts, gpointer data, sip->serveraddr = hosts->data; hosts = g_slist_remove(hosts, hosts->data); while (hosts) { - hosts = g_slist_remove(hosts, hosts->data); - g_free(hosts->data); - hosts = g_slist_remove(hosts, hosts->data); + void *tmp = hosts->data; + hosts = g_slist_remove(hosts, tmp); + hosts = g_slist_remove(hosts, tmp); + g_free(tmp); } /* create socket for incoming connections */ diff --git a/src/core/sipmsg.c b/src/core/sipmsg.c index e0288a3b..85e2cc3d 100644 --- a/src/core/sipmsg.c +++ b/src/core/sipmsg.c @@ -846,20 +846,20 @@ msn_import_html(const char *html, char **attributes, char **message) else if (!g_ascii_strncasecmp(c, "style=\"", 7)) { /* Parse inline CSS attributes */ - char *attributes; int attr_len = 0; c += 7; while (*(c + attr_len) != '\0' && *(c + attr_len) != '"') attr_len++; if (*(c + attr_len) == '"') { + char *css_attributes; char *attr_dir; - attributes = g_strndup(c, attr_len); - attr_dir = purple_markup_get_css_property(attributes, "direction"); + css_attributes = g_strndup(c, attr_len); + attr_dir = purple_markup_get_css_property(css_attributes, "direction"); + g_free(css_attributes); if (attr_dir && (!g_ascii_strncasecmp(attr_dir, "RTL", 3))) direction = '1'; g_free(attr_dir); - g_free(attributes); } } -- 2.11.4.GIT