Fix memory leaks

I was doing some code reviews of the 4.54 release and found a few memory
leaks. These are mostly in error paths.
diff --git a/audio/a2dp.c b/audio/a2dp.c
index 35d2fe2..3c8de82 100644
--- a/audio/a2dp.c
+++ b/audio/a2dp.c
@@ -1162,8 +1162,10 @@
 			return -ENOMEM;
 
 		av_err = avdtp_init(src, config);
-		if (av_err < 0)
+		if (av_err < 0) {
+			g_free(server);
 			return av_err;
+		}
 
 		bacpy(&server->src, src);
 		servers = g_slist_append(servers, server);
diff --git a/audio/control.c b/audio/control.c
index 77b29db..a6f930a 100644
--- a/audio/control.c
+++ b/audio/control.c
@@ -834,11 +834,13 @@
 	record = avrcp_tg_record();
 	if (!record) {
 		error("Unable to allocate new service record");
+		g_free(server);
 		return -1;
 	}
 
 	if (add_record_to_server(src, record) < 0) {
 		error("Unable to register AVRCP target service record");
+		g_free(server);
 		sdp_record_free(record);
 		return -1;
 	}
@@ -847,12 +849,14 @@
 	record = avrcp_ct_record();
 	if (!record) {
 		error("Unable to allocate new service record");
+		g_free(server);
 		return -1;
 	}
 
 	if (add_record_to_server(src, record) < 0) {
 		error("Unable to register AVRCP controller service record");
 		sdp_record_free(record);
+		g_free(server);
 		return -1;
 	}
 	server->ct_record_id = record->handle;
diff --git a/compat/dun.c b/compat/dun.c
index 7140bac..3d4dab4 100644
--- a/compat/dun.c
+++ b/compat/dun.c
@@ -86,6 +86,7 @@
 	}
 
 	close(sk);
+	free(dl);
 	return r;
 }
 
diff --git a/compat/dund.c b/compat/dund.c
index fc8ba30..f9847ea 100644
--- a/compat/dund.c
+++ b/compat/dund.c
@@ -568,21 +568,26 @@
 
 	io_init();
 
-	if (dun_init())
+	if (dun_init()) {
+		free(dst);
 		return -1;
+	}
 
 	/* Check non daemon modes first */
 	switch (mode) {
 	case SHOW:
 		do_show();
+		free(dst);
 		return 0;
 
 	case KILL:
 		do_kill(dst);
+		free(dst);
 		return 0;
 
 	case NONE:
 		printf(main_help, VERSION);
+		free(dst);
 		return 0;
 	}
 
@@ -612,6 +617,7 @@
 		src_dev = hci_devid(src);
 		if (src_dev < 0 || hci_devba(src_dev, &src_addr) < 0) {
 			syslog(LOG_ERR, "Invalid source. %s(%d)", strerror(errno), errno);
+			free(dst);
 			return -1;
 		}
 	}
@@ -634,5 +640,6 @@
 		break;
 	}
 
+	free(dst);
 	return 0;
 }
diff --git a/compat/pand.c b/compat/pand.c
index c3f3933..53f6c41 100644
--- a/compat/pand.c
+++ b/compat/pand.c
@@ -721,21 +721,26 @@
 	argv += optind;
 	optind = 0;
 
-	if (bnep_init())
+	if (bnep_init()) {
+		free(dst);
 		return -1;
+	}
 
 	/* Check non daemon modes first */
 	switch (mode) {
 	case SHOW:
 		do_show();
+		free(dst);
 		return 0;
 
 	case KILL:
 		do_kill(dst);
+		free(dst);
 		return 0;
 
 	case NONE:
 		printf(main_help, VERSION);
+		free(dst);
 		return 0;
 	}
 
@@ -766,12 +771,15 @@
 		if (src_dev < 0 || hci_devba(src_dev, &src_addr) < 0) {
 			syslog(LOG_ERR, "Invalid source. %s(%d)",
 						strerror(errno), errno);
+			free(dst);
 			return -1;
 		}
 	}
 
-	if (pidfile && write_pidfile())
+	if (pidfile && write_pidfile()) {
+		free(dst);
 		return -1;
+	}
 
 	if (dst) {
 		/* Disable cache invalidation */
diff --git a/cups/main.c b/cups/main.c
index 1bbc78c..0308f4d 100644
--- a/cups/main.c
+++ b/cups/main.c
@@ -599,6 +599,7 @@
 	loop = g_main_loop_new(NULL, TRUE);
 	g_main_loop_run(loop);
 
+	g_free(adapter);
 	dbus_connection_unref(conn);
 
 	return TRUE;
diff --git a/serial/proxy.c b/serial/proxy.c
index 88a414d..a77184b 100644
--- a/serial/proxy.c
+++ b/serial/proxy.c
@@ -1228,6 +1228,7 @@
 			debug("%s: %s", file, gerr->message);
 			g_error_free(gerr);
 			g_key_file_free(config);
+			g_strfreev(group_list);
 			return;
 		}
 
@@ -1238,6 +1239,7 @@
 			g_error_free(gerr);
 			g_key_file_free(config);
 			g_free(uuid_str);
+			g_strfreev(group_list);
 			return;
 		}
 
diff --git a/src/glib-helper.c b/src/glib-helper.c
index 727c55d..7d8fdb9 100644
--- a/src/glib-helper.c
+++ b/src/glib-helper.c
@@ -765,6 +765,7 @@
 
 	if (setsockopt(dd, SOL_HCI, HCI_FILTER, &nf, sizeof(nf)) < 0) {
 		err = errno;
+		g_free(cmd);
 		goto failed;
 	}
 
diff --git a/src/plugin.c b/src/plugin.c
index 852bdfa..2a4f608 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -139,8 +139,10 @@
 		add_plugin(NULL,  __bluetooth_builtin[i]);
 	}
 
-	if (strlen(PLUGINDIR) == 0)
+	if (strlen(PLUGINDIR) == 0) {
+		g_strfreev(disabled);
 		goto start;
+	}
 
 	debug("Loading plugins %s", PLUGINDIR);
 
diff --git a/tools/hcitool.c b/tools/hcitool.c
index faf4cb4..3f087e8 100644
--- a/tools/hcitool.c
+++ b/tools/hcitool.c
@@ -111,6 +111,7 @@
 		bt_free(str);
 	}
 
+	free(cl);
 	return 0;
 }
 
@@ -134,9 +135,12 @@
 	}
 
 	for (i = 0; i < cl->conn_num; i++, ci++)
-		if (!bacmp((bdaddr_t *) arg, &ci->bdaddr))
+		if (!bacmp((bdaddr_t *) arg, &ci->bdaddr)) {
+			free(cl);
 			return 1;
+		}
 
+	free(cl);
 	return 0;
 }
 
diff --git a/tools/l2ping.c b/tools/l2ping.c
index 55597cc..5d26ea6 100644
--- a/tools/l2ping.c
+++ b/tools/l2ping.c
@@ -240,6 +240,8 @@
 			id = ident;
 	}
 	stat(0);
+	free(send_buf);
+	free(recv_buf);
 	return;
 
 error:
diff --git a/tools/main.c b/tools/main.c
index ed82432..09e14d9 100644
--- a/tools/main.c
+++ b/tools/main.c
@@ -139,11 +139,13 @@
 
 	if (ioctl(ctl, RFCOMMGETDEVLIST, (void *) dl) < 0) {
 		perror("Can't get device list");
+		free(dl);
 		exit(1);
 	}
 
 	for (i = 0; i < dl->dev_num; i++)
 		print_dev_info(di + i);
+	free(dl);
 }
 
 static int create_dev(int ctl, int dev, uint32_t flags, bdaddr_t *bdaddr, int argc, char **argv)
@@ -249,12 +251,14 @@
 
 	if (ioctl(ctl, RFCOMMGETDEVLIST, (void *) dl) < 0) {
 		perror("Can't get device list");
+		free(dl);
 		exit(1);
 	}
 
 	for (i = 0; i < dl->dev_num; i++)
 		release_dev(ctl, (di + i)->id, 0);
 
+	free(dl);
 	return 0;
 }