From ebfc390d3004f3bfb7a15a8cd6740ef38a144a8e Mon Sep 17 00:00:00 2001 From: Nishant Chaprana Date: Wed, 6 Jan 2016 11:03:34 +0530 Subject: [PATCH] Fixed wifi_direct_foreach_connected_peers() API calling malloc(0) This patch fixes behaiour of wifi_direct_foreach_connected_peers() API when no connected peer at that time malloc(0) call was made and WIFI_DIRECT_OPERATION_FAILED was returned. But when no peer is conencted, at that time WIFI_DIRECT_ERROR_NONE should be returned and no malloc(0) call should be done. Change-Id: I266063ae0ecadef9b4c3959cd3bf69bb4bb886de Signed-off-by: Nishant Chaprana --- packaging/capi-network-wifi-direct.spec | 2 +- src/wifi-direct-client-proxy.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packaging/capi-network-wifi-direct.spec b/packaging/capi-network-wifi-direct.spec index 19c0eb0..a7bd09f 100644 --- a/packaging/capi-network-wifi-direct.spec +++ b/packaging/capi-network-wifi-direct.spec @@ -1,6 +1,6 @@ Name: capi-network-wifi-direct Summary: Network WiFi-Direct Library -Version: 1.2.43 +Version: 1.2.44 Release: 1 Group: Network & Connectivity/Wireless License: Apache-2.0 diff --git a/src/wifi-direct-client-proxy.c b/src/wifi-direct-client-proxy.c index 55697d5..04464af 100755 --- a/src/wifi-direct-client-proxy.c +++ b/src/wifi-direct-client-proxy.c @@ -2039,7 +2039,7 @@ int wifi_direct_accept_connection(char *mac_address) int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb cb, - void *user_data) + void *user_data) { __WDC_LOG_FUNC_START__; @@ -2110,7 +2110,7 @@ int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb cb, WDC_LOGD("Num of connected peers = %d", (int) rsp.param1); - if (num > 8 || num < 1) { + if (num > 8) { WDC_LOGE("Invalid number of connected peer(%d)", num); buff = (wfd_connected_peer_info_s*) g_try_malloc0_n(num, sizeof(wfd_connected_peer_info_s)); if (!buff) { @@ -2122,9 +2122,11 @@ int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb cb, res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff, num, sizeof(wfd_connected_peer_info_s)); pthread_mutex_unlock(&g_client_info.mutex); + } else if (num < 1) { WDC_LOGE("Invalid number of connected peer(%d)", num); pthread_mutex_unlock(&g_client_info.mutex); + } else { buff = (wfd_connected_peer_info_s*) g_try_malloc0_n(num, sizeof(wfd_connected_peer_info_s)); if (!buff) { -- 2.7.4