Skip to content

Commit

Permalink
memmory leak fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cmuhammedrafi committed Dec 6, 2024
1 parent bbd43eb commit 99aa438
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 49 deletions.
13 changes: 5 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,10 @@ set_target_properties(${MODULE_NAME} PROPERTIES


if(ENABLE_GNOME_NETWORKMANAGER)
target_sources(${MODULE_NAME} PRIVATE
gdbus/NetworkManagerGdbusProxy.cpp
gdbus/NetworkManagerGdbusMgr.cpp
gdbus/NetworkManagerGdbusClient.cpp
gdbus/NetworkManagerGdbusEvent.cpp
gdbus/NetworkManagerGdbusUtils.cpp )
target_sources(${MODULE_NAME} PRIVATE NetworkManagerGnomeProxy.cpp
NetworkManagerGnomeWIFI.cpp
NetworkManagerGnomeEvents.cpp
NetworkManagerGnomeUtils.cpp )
target_include_directories(${MODULE_NAME} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBNM_INCLUDE_DIRS})
target_link_libraries(${MODULE_NAME} PRIVATE ${LIBNM_LIBRARIES})
else()
Expand Down Expand Up @@ -173,6 +171,5 @@ write_config(PLUGINS LegacyPlugin_WiFiManagerAPIs CLASSNAME WiFiManager LOCATOR

if(ENABLE_UNIT_TESTING)
include(Tests/unit_test/unit_tests.cmake)
include(Tests/raspberrypi/NetworkManagerGdbusTest.cmake)
endif(ENABLE_UNIT_TESTING)

include(Tests/raspberrypi/NetworkManagerGdbusTest.cmake)
2 changes: 1 addition & 1 deletion NetworkManagerLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#endif

namespace NetworkManagerLogger {
static LogLevel gDefaultLogLevel = DEBUG_LEVEL;
static LogLevel gDefaultLogLevel = INFO_LEVEL;


#ifdef USE_RDK_LOGGER
Expand Down
6 changes: 3 additions & 3 deletions Tests/raspberrypi/NetworkManagerGdbusTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ pkg_check_modules(LIBNM REQUIRED libnm)

# Create the executable target
add_executable(${RPI_TEST}
Tests/raspberrypi/NetworkManagerGdbusTest.cpp
NetworkManagerLogger.cpp
gdbus/NetworkManagerGdbusClient.cpp
gdbus/NetworkManagerGdbusUtils.cpp
gdbus/NetworkManagerGdbusMgr.cpp
gdbus/NetworkManagerGdbusEvent.cpp
Tests/raspberrypi/NetworkManagerGdbusTest.cpp
)

# Set target properties for C++ standard
Expand All @@ -25,7 +25,7 @@ set_target_properties(${RPI_TEST} PROPERTIES
)

# Add compiler options, such as forced include of a specific header
target_compile_options(${RPI_TEST} PRIVATE -Wall -include ${CMAKE_SOURCE_DIR}/INetworkManager.h)
target_compile_options(${RPI_TEST} PRIVATE -g -Wall -include ${CMAKE_SOURCE_DIR}/INetworkManager.h)

target_include_directories(${RPI_TEST} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBNM_INCLUDE_DIRS} ${GIO_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR})
target_include_directories(${RPI_TEST} PRIVATE gdbus)
Expand All @@ -36,4 +36,4 @@ target_link_libraries(${RPI_TEST} ${NAMESPACE}Core::${NAMESPACE}Core ${GLIB_LIBR
target_include_directories(${RPI_TEST} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

# Install the executable to the appropriate location
install(TARGETS ${RPI_TEST} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(TARGETS ${RPI_TEST} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
16 changes: 10 additions & 6 deletions gdbus/NetworkManagerGdbusClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ namespace WPEFramework
const char *interfaceName = NULL;
G_VARIANT_LOOKUP(gVarConn, "type", "&s", &connTyp);
G_VARIANT_LOOKUP(gVarConn, "interface-name", "&s", &interfaceName);
if((strcmp(connTyp, "802-11-wireless") == 0) && strcmp(interfaceName, GnomeUtils::getWifiIfname()) != 0 )
if((strcmp(connTyp, "802-11-wireless") == 0) && strcmp(interfaceName, GnomeUtils::getWifiIfname()) == 0 )
{
// 802-11-wireless.ssid: <ssid>
GVariant *setting = NULL;
Expand Down Expand Up @@ -197,7 +197,10 @@ namespace WPEFramework
}

if(ssids.empty())
{
NMLOG_WARNING("no Known SSID list empty");
return false;
}
return true;
}

Expand Down Expand Up @@ -230,17 +233,20 @@ namespace WPEFramework
}

g_variant_get(result, "o", &activeApPath);
if(g_strdup(activeApPath) != NULL && g_strcmp0(activeApPath, "/") != 0)

if(activeApPath != NULL && g_strcmp0(activeApPath, "/") != 0)
{
//NMLOG_DEBUG("ActiveAccessPoint property path %s", activeApPath);
if(GnomeUtils::getApDetails(m_dbus, g_strdup(activeApPath), ssidinfo))
if(GnomeUtils::getApDetails(m_dbus, activeApPath, ssidinfo))
{
ret = true;
}
}
else
NMLOG_WARNING("active access point not found");

if(activeApPath != NULL)
g_free(activeApPath);
g_variant_unref(result);
g_object_unref(wProxy);
return ret;
Expand Down Expand Up @@ -280,9 +286,7 @@ namespace WPEFramework
while (g_variant_iter_loop(iter, "o", &apPath)) {
Exchange::INetworkManager::WiFiSSIDInfo wifiInfo{};
NMLOG_DEBUG("Access Point Path: %s", apPath);
if(!GnomeUtils::getApDetails(m_dbus, apPath, wifiInfo))
NMLOG_WARNING("getApDetails failed");
else
if(GnomeUtils::getApDetails(m_dbus, apPath, wifiInfo))
ssids.push_back(wifiInfo.ssid);
}

Expand Down
3 changes: 2 additions & 1 deletion gdbus/NetworkManagerGdbusEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,11 @@ namespace WPEFramework

void NetworkManagerEvents::onAvailableSSIDsCb(const char* wifiDevicePath)
{
NMLOG_DEBUG("wifi scanning completed ...");
if(_NetworkManagerEvents->doScanNotify == false) {
return;
}
NMLOG_DEBUG("wifi scanning completed ...");

_NetworkManagerEvents->doScanNotify = false;
GDBusProxy* wProxy = nullptr;
GError* error = nullptr;
Expand Down
4 changes: 2 additions & 2 deletions gdbus/NetworkManagerGdbusMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ namespace WPEFramework
NULL,
&error
);
if (nmProxy == NULL|| error != NULL) {

if (nmProxy == NULL || error != NULL) {
g_dbus_error_strip_remote_error(error);
NMLOG_FATAL("Error creating D-Bus proxy: %s", error->message);
g_error_free(error);
Expand Down
66 changes: 38 additions & 28 deletions gdbus/NetworkManagerGdbusUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,12 @@ namespace WPEFramework
{
GVariant* result = NULL;
result = g_dbus_proxy_get_cached_property(proxy, propertiy);
if (!result) {
if (result == NULL) {
NMLOG_ERROR("Failed to get '%s' properties", propertiy);
return false;
}
if (result != NULL && g_variant_is_of_type (result, G_VARIANT_TYPE_UINT32)) {

if (g_variant_is_of_type (result, G_VARIANT_TYPE_UINT32)) {
*value = g_variant_get_uint32(result);
//NMLOG_DEBUG("%s: %d", propertiy, *value);
}
Expand Down Expand Up @@ -247,7 +247,10 @@ namespace WPEFramework
if (devicesVar) {
const gchar *iface = g_variant_get_string(devicesVar, NULL);
if(iface != NULL)
{
properties.interface = iface;
//g_free(iface);
}
//NMLOG_DEBUG("Interface: %s", iface);
g_variant_unref(devicesVar);
}
Expand Down Expand Up @@ -288,25 +291,26 @@ namespace WPEFramework
}

GVariantIter* iter;
const gchar* devicePath;
gchar* devicePath = NULL;
g_variant_get(devicesVar, "(ao)", &iter);
while (g_variant_iter_loop(iter, "o", &devicePath))
{
if(devicePath != NULL )
if(devicePath == NULL )
continue;

if(getDevicePropertiesByPath(m_dbus, devicePath, properties) && properties.interface == ifaceName)
{
if(getDevicePropertiesByPath(m_dbus, devicePath, properties) && properties.interface == ifaceName)
{
properties.path = devicePath;
ret = true;
break;
}
properties.path = devicePath;
g_free(devicePath);
ret = true;
break;
}
g_free(devicePath);
}
g_variant_iter_free(iter);

g_variant_iter_free(iter);
if(!ret)
NMLOG_ERROR("'%s' interface not found", ifaceName);

if(devicesVar)
g_variant_unref(devicesVar);
if(nmProxy)
Expand Down Expand Up @@ -347,10 +351,11 @@ namespace WPEFramework
if (g_variant_is_of_type (result, (const GVariantType *) "(o)"))
{
g_variant_get(result, "(o)", &device_path);
if(g_strdup(device_path) != NULL)
if(device_path != NULL)
{
path = std::string(g_strdup(device_path));
path = std::string(device_path);
ret = true;
g_free(device_path);
}
}
//NMLOG_DEBUG("%s device path %s", iface_name, path.c_str());
Expand All @@ -364,29 +369,27 @@ namespace WPEFramework
uint8_t strength = 0;
NM80211Mode mode = NM_802_11_MODE_UNKNOWN;
bool ret = false;
char *_bssid = NULL;
GVariant* result = NULL;
GVariant* ssidVariant = NULL;

GDBusProxy* proxy = m_dbus.getNetworkManagerAccessPointProxy(apPath);

if (proxy == NULL) {
return false;
}

gsize ssid_length = 0;
result = g_dbus_proxy_get_cached_property(proxy,"Ssid");
if (!result) {
ssidVariant = g_dbus_proxy_get_cached_property(proxy,"Ssid");
if (!ssidVariant) {
NMLOG_ERROR("Failed to get AP properties.");
g_object_unref(proxy);
return false;
}

const guchar *ssid_data = static_cast<const guchar*>(g_variant_get_fixed_array(result, &ssid_length, sizeof(guchar)));
const guchar *ssid_data = static_cast<const guchar*>(g_variant_get_fixed_array(ssidVariant, &ssid_length, sizeof(guchar)));
if (ssid_data && ssid_length > 0 && ssid_length <= 32)
{
GVariant* result = NULL;
gchar *_bssid = NULL;
wifiInfo.ssid.assign(reinterpret_cast<const char*>(ssid_data), ssid_length);
g_variant_unref(result);

result = g_dbus_proxy_get_cached_property(proxy,"HwAddress");
if (!result) {
NMLOG_ERROR("Failed to get AP properties.");
Expand All @@ -396,9 +399,10 @@ namespace WPEFramework
g_variant_get(result, "s", &_bssid);
if(_bssid != NULL) {
wifiInfo.bssid.assign(_bssid);
g_free(_bssid);
}
g_variant_unref(result);

result = NULL;
result = g_dbus_proxy_get_cached_property(proxy,"Strength");
if (!result) {
NMLOG_ERROR("Failed to get AP properties.");
Expand All @@ -416,7 +420,7 @@ namespace WPEFramework
GnomeUtils::getCachedPropertyU(proxy, "Frequency", &freq);
GnomeUtils::getCachedPropertyU(proxy, "MaxBitrate", &bitrate);

wifiInfo.frequency = static_cast<double>(freq);
wifiInfo.frequency = std::to_string((double)freq/1000);
wifiInfo.rate = std::to_string(bitrate);
wifiInfo.security = static_cast<Exchange::INetworkManager::WIFISecurityMode>(wifiSecurityModeFromApFlags(flags, wpaFlags, rsnFlags));

Expand All @@ -435,7 +439,10 @@ namespace WPEFramework
ret = false;
}

g_object_unref(proxy);
if(ssidVariant)
g_variant_unref(ssidVariant);
if(proxy)
g_object_unref(proxy);

return ret;
}
Expand Down Expand Up @@ -482,15 +489,18 @@ namespace WPEFramework
}

GVariantIter* iter;
const gchar* connPath = NULL;
gchar* connPath = NULL;
g_variant_get(result, "ao", &iter);
while (g_variant_iter_loop(iter, "o", &connPath)) {
if(g_strdup(connPath) != NULL && g_strcmp0(connPath, "/") != 0)
if(connPath == NULL)
continue;
if(g_strcmp0(connPath, "/") != 0)
{
paths.push_back(connPath);
// NMLOG_DEBUG("AvailableConnections Path: %s", connPath);
ret = true;
}
g_free(connPath);
}

g_variant_iter_free(iter);
Expand Down

0 comments on commit 99aa438

Please sign in to comment.