diff libpurple/protocols/oscar/family_feedbag.c @ 17191:1927f4ead3ca

Make all the oscar memory allocations and frees use the glib functions to avoid problems when mixing C runtimes.
author Daniel Atallah <daniel.atallah@gmail.com>
date Tue, 22 May 2007 18:56:09 +0000
parents 0a3ae69a25ea
children f80f7e1047be
line wrap: on
line diff
--- a/libpurple/protocols/oscar/family_feedbag.c	Tue May 22 13:00:00 2007 +0000
+++ b/libpurple/protocols/oscar/family_feedbag.c	Tue May 22 18:56:09 2007 +0000
@@ -81,7 +81,7 @@
 	if (newlen > 0) {
 		guint8 *newdata;
 
-		newdata = (guint8 *)malloc((newlen)*sizeof(guint8));
+		newdata = (guint8 *)g_malloc((newlen)*sizeof(guint8));
 		newlen = 0;
 		if (group->gid == 0x0000) {
 			for (cur=list; cur; cur=cur->next)
@@ -94,7 +94,7 @@
 		}
 		aim_tlvlist_replace_raw(&group->data, 0x00c8, newlen, newdata);
 
-		free(newdata);
+		g_free(newdata);
 	}
 }
 
@@ -115,11 +115,11 @@
 	gboolean exists;
 	struct aim_ssi_item *cur, *new;
 
-	new = (struct aim_ssi_item *)malloc(sizeof(struct aim_ssi_item));
+	new = (struct aim_ssi_item *)g_malloc(sizeof(struct aim_ssi_item));
 
 	/* Set the name */
 	if (name) {
-		new->name = (char *)malloc((strlen(name)+1)*sizeof(char));
+		new->name = (char *)g_malloc((strlen(name)+1)*sizeof(char));
 		strcpy(new->name, name);
 	} else
 		new->name = NULL;
@@ -213,9 +213,9 @@
 	}
 
 	/* Free the removed item */
-	free(del->name);
+	g_free(del->name);
 	aim_tlvlist_free(&del->data);
-	free(del);
+	g_free(del);
 
 	return 0;
 }
@@ -510,7 +510,7 @@
 		for (cur1=od->ssi.local; cur1 && (n < 15); cur1=cur1->next) {
 			if (!aim_ssi_itemlist_find(od->ssi.official, cur1->gid, cur1->bid)) {
 				n++;
-				new = (struct aim_ssi_tmp *)malloc(sizeof(struct aim_ssi_tmp));
+				new = (struct aim_ssi_tmp *)g_malloc(sizeof(struct aim_ssi_tmp));
 				new->action = SNAC_SUBTYPE_FEEDBAG_ADD;
 				new->ack = 0xffff;
 				new->name = NULL;
@@ -530,7 +530,7 @@
 		for (cur1=od->ssi.official; cur1 && (n < 15); cur1=cur1->next) {
 			if (!aim_ssi_itemlist_find(od->ssi.local, cur1->gid, cur1->bid)) {
 				n++;
-				new = (struct aim_ssi_tmp *)malloc(sizeof(struct aim_ssi_tmp));
+				new = (struct aim_ssi_tmp *)g_malloc(sizeof(struct aim_ssi_tmp));
 				new->action = SNAC_SUBTYPE_FEEDBAG_DEL;
 				new->ack = 0xffff;
 				new->name = NULL;
@@ -551,7 +551,7 @@
 			cur2 = aim_ssi_itemlist_find(od->ssi.official, cur1->gid, cur1->bid);
 			if (cur2 && (aim_ssi_itemlist_cmp(cur1, cur2))) {
 				n++;
-				new = (struct aim_ssi_tmp *)malloc(sizeof(struct aim_ssi_tmp));
+				new = (struct aim_ssi_tmp *)g_malloc(sizeof(struct aim_ssi_tmp));
 				new->action = SNAC_SUBTYPE_FEEDBAG_MOD;
 				new->ack = 0xffff;
 				new->name = NULL;
@@ -609,25 +609,25 @@
 	while (cur) {
 		del = cur;
 		cur = cur->next;
-		free(del->name);
+		g_free(del->name);
 		aim_tlvlist_free(&del->data);
-		free(del);
+		g_free(del);
 	}
 
 	cur = od->ssi.local;
 	while (cur) {
 		del = cur;
 		cur = cur->next;
-		free(del->name);
+		g_free(del->name);
 		aim_tlvlist_free(&del->data);
-		free(del);
+		g_free(del);
 	}
 
 	curtmp = od->ssi.pending;
 	while (curtmp) {
 		deltmp = curtmp;
 		curtmp = curtmp->next;
-		free(deltmp);
+		g_free(deltmp);
 	}
 
 	od->ssi.numitems = 0;
@@ -672,7 +672,7 @@
 			char *alias = aim_ssi_getalias(od->ssi.local, NULL, cur->name);
 			aim_ssi_addbuddy(od, cur->name, "orphans", alias, NULL, NULL, 0);
 			aim_ssi_delbuddy(od, cur->name, NULL);
-			free(alias);
+			g_free(alias);
 		}
 		cur = next;
 	}
@@ -929,7 +929,7 @@
 	aim_ssi_delbuddy(od, sn, oldgn);
 	aim_ssi_addbuddy(od, sn, newgn, alias, NULL, NULL, waitingforauth);
 
-	free(alias);
+	g_free(alias);
 
 	return 0;
 }
@@ -1012,8 +1012,8 @@
 	if (!(group = aim_ssi_itemlist_finditem(od->ssi.local, oldgn, NULL, AIM_SSI_TYPE_GROUP)))
 		return -EINVAL;
 
-	free(group->name);
-	group->name = (char *)malloc((strlen(newgn)+1)*sizeof(char));
+	g_free(group->name);
+	group->name = (char *)g_malloc((strlen(newgn)+1)*sizeof(char));
 	strcpy(group->name, newgn);
 
 	/* Sync our local list with the server list */
@@ -1086,12 +1086,12 @@
 	}
 
 	/* Need to add the 0x00d5 TLV to the TLV chain */
-	csumdata = (guint8 *)malloc((iconsumlen+2)*sizeof(guint8));
+	csumdata = (guint8 *)g_malloc((iconsumlen+2)*sizeof(guint8));
 	aimutil_put8(&csumdata[0], 0x00);
 	aimutil_put8(&csumdata[1], iconsumlen);
 	memcpy(&csumdata[2], iconsum, iconsumlen);
 	aim_tlvlist_replace_raw(&tmp->data, 0x00d5, (iconsumlen+2) * sizeof(guint8), csumdata);
-	free(csumdata);
+	g_free(csumdata);
 
 	/* Need to add the 0x0131 TLV to the TLV chain, used to cache the icon */
 	aim_tlvlist_replace_noval(&tmp->data, 0x0131);
@@ -1188,7 +1188,7 @@
 
 	byte_stream_init(&bstream, tlv->value, tlv->length);
 
-	maxitems = (guint16 *)malloc((tlv->length/2)*sizeof(guint16));
+	maxitems = (guint16 *)g_malloc((tlv->length/2)*sizeof(guint16));
 
 	for (i=0; i<(tlv->length/2); i++)
 		maxitems[i] = byte_stream_get16(&bstream);
@@ -1197,7 +1197,7 @@
 		ret = userfunc(od, conn, frame, tlv->length/2, maxitems);
 
 	aim_tlvlist_free(&tlvlist);
-	free(maxitems);
+	g_free(maxitems);
 
 	return ret;
 }
@@ -1283,7 +1283,7 @@
 		type = byte_stream_get16(bs);
 		data = aim_tlvlist_readlen(bs, byte_stream_get16(bs));
 		aim_ssi_itemlist_add(&od->ssi.official, name, gid, bid, type, data);
-		free(name);
+		g_free(name);
 		aim_tlvlist_free(&data);
 	}
 
@@ -1411,7 +1411,7 @@
 		if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
 			ret = userfunc(od, conn, frame, type, name);
 
-		free(name);
+		g_free(name);
 	}
 
 	return ret;
@@ -1447,9 +1447,9 @@
 		/* Replace the 2 local items with the given one */
 		if ((item = aim_ssi_itemlist_find(od->ssi.local, gid, bid))) {
 			item->type = type;
-			free(item->name);
+			g_free(item->name);
 			if (name) {
-				item->name = (char *)malloc((strlen(name)+1)*sizeof(char));
+				item->name = (char *)g_malloc((strlen(name)+1)*sizeof(char));
 				strcpy(item->name, name);
 			} else
 				item->name = NULL;
@@ -1459,9 +1459,9 @@
 
 		if ((item = aim_ssi_itemlist_find(od->ssi.official, gid, bid))) {
 			item->type = type;
-			free(item->name);
+			g_free(item->name);
 			if (name) {
-				item->name = (char *)malloc((strlen(name)+1)*sizeof(char));
+				item->name = (char *)g_malloc((strlen(name)+1)*sizeof(char));
 				strcpy(item->name, name);
 			} else
 				item->name = NULL;
@@ -1472,7 +1472,7 @@
 		if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
 			ret = userfunc(od, conn, frame);
 
-		free(name);
+		g_free(name);
 		aim_tlvlist_free(&data);
 	}
 
@@ -1543,7 +1543,7 @@
 				/* Make sure cur->item is still valid memory */
 				if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {
 					if (cur->item->name) {
-						cur->name = (char *)malloc((strlen(cur->item->name)+1)*sizeof(char));
+						cur->name = (char *)g_malloc((strlen(cur->item->name)+1)*sizeof(char));
 						strcpy(cur->name, cur->item->name);
 					}
 					aim_ssi_itemlist_del(&od->ssi.local, cur->item);
@@ -1555,9 +1555,9 @@
 				if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {
 					struct aim_ssi_item *cur1;
 					if ((cur1 = aim_ssi_itemlist_find(od->ssi.official, cur->item->gid, cur->item->bid))) {
-						free(cur->item->name);
+						g_free(cur->item->name);
 						if (cur1->name) {
-							cur->item->name = (char *)malloc((strlen(cur1->name)+1)*sizeof(char));
+							cur->item->name = (char *)g_malloc((strlen(cur1->name)+1)*sizeof(char));
 							strcpy(cur->item->name, cur1->name);
 						} else
 							cur->item->name = NULL;
@@ -1589,9 +1589,9 @@
 				if (aim_ssi_itemlist_valid(od->ssi.local, cur->item)) {
 					struct aim_ssi_item *cur1;
 					if ((cur1 = aim_ssi_itemlist_find(od->ssi.official, cur->item->gid, cur->item->bid))) {
-						free(cur1->name);
+						g_free(cur1->name);
 						if (cur->item->name) {
-							cur1->name = (char *)malloc((strlen(cur->item->name)+1)*sizeof(char));
+							cur1->name = (char *)g_malloc((strlen(cur->item->name)+1)*sizeof(char));
 							strcpy(cur1->name, cur->item->name);
 						} else
 							cur1->name = NULL;
@@ -1620,8 +1620,8 @@
 	while (cur && (cur->ack != 0xffff)) {
 		del = cur;
 		cur = cur->next;
-		free(del->name);
-		free(del);
+		g_free(del->name);
+		g_free(del);
 	}
 	od->ssi.pending = cur;
 
@@ -1757,8 +1757,8 @@
 	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
 		ret = userfunc(od, conn, frame, sn, msg);
 
-	free(sn);
-	free(msg);
+	g_free(sn);
+	g_free(msg);
 
 	return ret;
 }
@@ -1831,8 +1831,8 @@
 	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
 		ret = userfunc(od, conn, frame, sn, msg);
 
-	free(sn);
-	free(msg);
+	g_free(sn);
+	g_free(msg);
 
 	return ret;
 }
@@ -1918,8 +1918,8 @@
 	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
 		ret = userfunc(od, conn, frame, sn, reply, msg);
 
-	free(sn);
-	free(msg);
+	g_free(sn);
+	g_free(msg);
 
 	return ret;
 }
@@ -1943,7 +1943,7 @@
 	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
 		ret = userfunc(od, conn, frame, sn);
 
-	free(sn);
+	g_free(sn);
 
 	return ret;
 }