summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSyed Ibrahim M <syedibra@broadcom.com>2012-06-05 17:59:45 +0530
committerMatthew Xie <mattx@google.com>2012-07-14 11:19:22 -0700
commit33b0957d838b348e9459ed5b988cf59344a0d41c (patch)
treee18d6e87c632716a4d342fa57428b946fdef32cb
parent6bc6378d9fa5f2bbb07d0b79dad7ccd2dc68f8b1 (diff)
downloadexternal_bluetooth_bluedroid-33b0957d838b348e9459ed5b988cf59344a0d41c.zip
external_bluetooth_bluedroid-33b0957d838b348e9459ed5b988cf59344a0d41c.tar.gz
external_bluetooth_bluedroid-33b0957d838b348e9459ed5b988cf59344a0d41c.tar.bz2
Fixed the BTIF_HL to exit the select thread and close the signal FDs when cleanup() is called. This stops the signal FDs to be leaked for every BT on/off cycle
Closed the open FDs in univ_linux.c to stop FD leaks during BT on/off cycles Change-Id: I86af438dc1186e12aa1f18fd44bcc89343ef5489
-rwxr-xr-xbtif/src/btif_hl.c41
-rwxr-xr-xudrv/ulinux/unv_linux.c5
2 files changed, 45 insertions, 1 deletions
diff --git a/btif/src/btif_hl.c b/btif/src/btif_hl.c
index 5ef3af8..2b2ed14 100755
--- a/btif/src/btif_hl.c
+++ b/btif/src/btif_hl.c
@@ -53,6 +53,8 @@
*
*
***********************************************************************************/
+#define LOG_TAG "BTIF_HL"
+
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
@@ -85,7 +87,6 @@
#include "btif_storage.h"
#include "btu.h"
-
extern int btif_hl_update_maxfd( int max_org_s);
extern void btif_hl_select_monitor_callback( fd_set *p_cur_set, fd_set *p_org_set );
extern void btif_hl_select_wakeup_callback( fd_set *p_org_set , int wakeup_signal );
@@ -121,6 +122,7 @@ static BUFFER_Q soc_queue;
static inline int btif_hl_select_wakeup(void);
static inline int btif_hl_select_exit(void);
static inline int btif_hl_select_close_connected(void);
+static inline int btif_hl_close_select_thread(void);
static UINT8 btif_hl_get_next_app_id(void);
static int btif_hl_get_next_channel_id(UINT8 app_id);
static void btif_hl_init_next_app_id(void);
@@ -4561,6 +4563,7 @@ static void cleanup( void ){
}
btif_hl_disable();
+ btif_hl_close_select_thread();
}
static const bthl_interface_t bthlInterface = {
@@ -5028,6 +5031,36 @@ static inline int btif_hl_select_close_connected(void){
BTIF_TRACE_DEBUG0("btif_hl_select_close_connected");
return send(signal_fds[1], &sig_on, sizeof(sig_on), 0);
}
+
+/*******************************************************************************
+**
+** Function btif_hl_close_select_thread
+**
+** Description send signal to close the thread and then close all signal FDs
+**
+** Returns int
+**
+*******************************************************************************/
+static inline int btif_hl_close_select_thread(void)
+{
+ int result = 0;
+ char sig_on = btif_hl_signal_select_exit;
+ BTIF_TRACE_DEBUG0("btif_hl_signal_select_exit");
+ result = send(signal_fds[1], &sig_on, sizeof(sig_on), 0);
+ /* Cleanup signal sockets */
+ if(signal_fds[0] != -1)
+ {
+ close(signal_fds[0]);
+ signal_fds[0] = -1;
+ }
+ if(signal_fds[1] != -1)
+ {
+ close(signal_fds[1]);
+ signal_fds[1] = -1;
+ }
+ return result;
+}
+
/*******************************************************************************
**
** Function btif_hl_select_wake_reset
@@ -5121,6 +5154,12 @@ static void *btif_hl_select_thread(void *arg){
{
btif_hl_select_wakeup_callback(&org_set, r);
}
+ else if( r == btif_hl_signal_select_exit)
+ {
+ btif_hl_thread_cleanup();
+ BTIF_TRACE_DEBUG0("Exit hl_select_thread for btif_hl_signal_select_exit");
+ return 0;
+ }
}
btif_hl_select_monitor_callback(&curr_set, &org_set);
diff --git a/udrv/ulinux/unv_linux.c b/udrv/ulinux/unv_linux.c
index 2f58265..75e61c1 100755
--- a/udrv/ulinux/unv_linux.c
+++ b/udrv/ulinux/unv_linux.c
@@ -657,13 +657,17 @@ int unv_read_key_iter( const char *path,
if (fstat(fd, &st) != 0)
{
error("stat failed (%s)", strerror(errno));
+ close(fd);
return -1;
}
p_buf = malloc(st.st_size + 1);
if (!p_buf)
+ {
+ close(fd);
return -1;
+ }
p = p_buf;
@@ -671,6 +675,7 @@ int unv_read_key_iter( const char *path,
{
error("read failed %s", strerror(errno));
free(p_buf);
+ close(fd);
return -1;
}