summary refs log tree commit diff stats
path: root/src/common/url.c
diff options
context:
space:
mode:
authorTingPing <tingping@tingping.se>2014-12-28 06:37:25 -0500
committerTingPing <tingping@tingping.se>2014-12-28 06:44:44 -0500
commit83032b1aa3c3e5910c5cfd3e0ea1d25827f56475 (patch)
tree9be32a04d3070eac82177e11d182dad40a63baa7 /src/common/url.c
parentc4cb1b25ec06a5b0cb718c6f8e74630df9a9bc64 (diff)
Use glib for all allocations
- Removes need to check for malloc failure
- Removes need for NULL checks on free
- Adds checks for integer overflows
- Removes some extra memset calls
- Removes chance of mixing libc and glib malloc/free
Diffstat (limited to 'src/common/url.c')
-rw-r--r--src/common/url.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/src/common/url.c b/src/common/url.c
index c5a3e718..0354d98c 100644
--- a/src/common/url.c
+++ b/src/common/url.c
@@ -53,7 +53,7 @@ static gboolean match_path (const char *word, int *start, int *end);
 static int
 url_free (char *url, void *data)
 {
-	free (url);
+	g_free (url);
 	return TRUE;
 }
 
@@ -124,13 +124,7 @@ url_add (char *urltext, int len)
 		return;
 	}
 
-	data = malloc (len + 1);
-	if (!data)
-	{
-		return;
-	}
-	memcpy (data, urltext, len);
-	data[len] = 0;
+	data = g_strndup (urltext, len);
 
 	if (data[len - 1] == '.')	/* chop trailing dot */
 	{
@@ -151,7 +145,7 @@ url_add (char *urltext, int len)
 	/* the URL is saved already, only continue if we need the URL grabber too */
 	if (!prefs.hex_url_grabber)
 	{
-		free (data);
+		g_free (data);
 		return;
 	}
 
@@ -163,7 +157,7 @@ url_add (char *urltext, int len)
 
 	if (url_find (data))
 	{
-		free (data);
+		g_free (data);
 		return;
 	}
 
@@ -180,7 +174,7 @@ url_add (char *urltext, int len)
 
 			pos = tree_remove_at_pos (url_tree, 0);
 			g_tree_remove (url_btree, pos);
-			free (pos);
+			g_free (pos);
 		}
 	}