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.
This commit is contained in:
Steve Grubb 2009-09-25 16:23:02 -04:00 committed by Johan Hedberg
parent 11091ffeeb
commit 2e926fb016
12 changed files with 44 additions and 6 deletions

View File

@ -1162,8 +1162,10 @@ proceed:
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);

View File

@ -834,11 +834,13 @@ int avrcp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config)
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 @@ int avrcp_register(DBusConnection *conn, const bdaddr_t *src, GKeyFile *config)
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;

View File

@ -86,6 +86,7 @@ static int for_each_port(int (*func)(struct rfcomm_dev_info *, unsigned long), u
}
close(sk);
free(dl);
return r;
}

View File

@ -568,21 +568,26 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
break;
}
free(dst);
return 0;
}

View File

@ -721,21 +721,26 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
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 */

View File

@ -599,6 +599,7 @@ static gboolean list_printers(void)
loop = g_main_loop_new(NULL, TRUE);
g_main_loop_run(loop);
g_free(adapter);
dbus_connection_unref(conn);
return TRUE;

View File

@ -1228,6 +1228,7 @@ static void serial_proxy_init(struct serial_adapter *adapter)
debug("%s: %s", file, gerr->message);
g_error_free(gerr);
g_key_file_free(config);
g_strfreev(group_list);
return;
}
@ -1238,6 +1239,7 @@ static void serial_proxy_init(struct serial_adapter *adapter)
g_error_free(gerr);
g_key_file_free(config);
g_free(uuid_str);
g_strfreev(group_list);
return;
}

View File

@ -765,6 +765,7 @@ int bt_acl_encrypt(const bdaddr_t *src, const bdaddr_t *dst,
if (setsockopt(dd, SOL_HCI, HCI_FILTER, &nf, sizeof(nf)) < 0) {
err = errno;
g_free(cmd);
goto failed;
}

View File

@ -139,8 +139,10 @@ gboolean plugin_init(GKeyFile *config)
add_plugin(NULL, __bluetooth_builtin[i]);
}
if (strlen(PLUGINDIR) == 0)
if (strlen(PLUGINDIR) == 0) {
g_strfreev(disabled);
goto start;
}
debug("Loading plugins %s", PLUGINDIR);

View File

@ -111,6 +111,7 @@ static int conn_list(int s, int dev_id, long arg)
bt_free(str);
}
free(cl);
return 0;
}
@ -134,9 +135,12 @@ static int find_conn(int s, int dev_id, long arg)
}
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;
}

View File

@ -240,6 +240,8 @@ static void ping(char *svr)
id = ident;
}
stat(0);
free(send_buf);
free(recv_buf);
return;
error:

View File

@ -139,11 +139,13 @@ static void print_dev_list(int ctl, int flags)
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 @@ static int release_all(int ctl)
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;
}