Skip to content

Commit b4a66cb

Browse files
RDKEMW-6189, RDKEMW-6300: Fix RemoveKnownSSID response and address memory leak in NetworkManager (#197)
* RDKEMW-6300 fix for memory leak in NetworkManager * updated the log line
1 parent 35690e0 commit b4a66cb

File tree

4 files changed

+111
-42
lines changed

4 files changed

+111
-42
lines changed

plugin/NetworkManagerSecretAgent.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,14 @@ namespace WPEFramework
233233
&error);
234234

235235
if (!agentRegID) {
236-
NMLOG_ERROR("Failed to register object: %s", error->message);
237-
g_error_free(error);
236+
NMLOG_ERROR("Failed to register object:");
237+
if (error != NULL)
238+
{
239+
NMLOG_ERROR("Error : %s", error->message);
240+
g_error_free(error);
241+
}
238242
g_dbus_node_info_unref(node_info);
239-
return ;
243+
return;
240244
}
241245

242246
NMLOG_INFO("Object registered with ID: %u", agentRegID);

plugin/gnome/NetworkManagerGnomeProxy.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,10 @@ namespace WPEFramework
8080
// initialize the NMClient object
8181
client = nm_client_new(NULL, &error);
8282
if (client == NULL) {
83-
NMLOG_FATAL("Error initializing NMClient: %s", error->message);
84-
g_error_free(error);
83+
if (error) {
84+
NMLOG_FATAL("Error initializing NMClient: %s", error->message);
85+
g_error_free(error);
86+
}
8587
return;
8688
}
8789

plugin/gnome/NetworkManagerGnomeWIFI.cpp

Lines changed: 94 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ namespace WPEFramework
5252

5353
m_client = nm_client_new(NULL, &error);
5454
if (!m_client || !m_loop) {
55-
NMLOG_ERROR("Could not connect to NetworkManager: %s.", error->message);
56-
g_error_free(error);
55+
if (error) {
56+
NMLOG_ERROR("Could not connect to NetworkManager: %s.", error->message);
57+
g_error_free(error);
58+
}
5759
return false;
5860
}
5961
return true;
@@ -337,23 +339,28 @@ namespace WPEFramework
337339

338340
static void disconnectCb(GObject *object, GAsyncResult *result, gpointer user_data)
339341
{
340-
NMDevice *device = NM_DEVICE(object);
341-
GError *error = NULL;
342-
wifiManager *_wifiManager = (static_cast<wifiManager*>(user_data));
342+
NMDevice *device = NM_DEVICE(object);
343+
GError *error = NULL;
344+
wifiManager *_wifiManager = static_cast<wifiManager*>(user_data);
343345

344346
NMLOG_DEBUG("Disconnecting... ");
345347
_wifiManager->m_isSuccess = true;
346-
if (!nm_device_disconnect_finish(device, result, &error)) {
347-
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
348-
return;
349-
350-
NMLOG_ERROR("Device '%s' (%s) disconnecting failed: %s",
351-
nm_device_get_iface(device),
352-
nm_object_get_path(NM_OBJECT(device)),
353-
error->message);
354-
g_error_free(error);
355-
_wifiManager->quit(device);
356-
_wifiManager->m_isSuccess = false;
348+
if (!nm_device_disconnect_finish(device, result, &error))
349+
{
350+
NMLOG_ERROR("device '%s' disconnect failed !", nm_device_get_iface(device));
351+
if(error != NULL)
352+
{
353+
if(g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
354+
{
355+
NMLOG_ERROR("something went wrong no matching gerror found !");
356+
}
357+
else
358+
{
359+
NMLOG_ERROR("Device path '%s': %s", nm_object_get_path(NM_OBJECT(device)), error->message);
360+
}
361+
g_error_free(error);
362+
}
363+
_wifiManager->m_isSuccess = false;
357364
}
358365
_wifiManager->quit(device);
359366
}
@@ -566,8 +573,12 @@ namespace WPEFramework
566573
NULL,
567574
&error))
568575
{
569-
NMLOG_ERROR("ca certificate add failed: %s", error->message);
570-
g_error_free(error);
576+
NMLOG_ERROR("ca certificate add failed");
577+
if(error != NULL)
578+
{
579+
NMLOG_ERROR("Error message %s", error->message);
580+
g_error_free(error);
581+
}
571582
return false;
572583
}
573584

@@ -577,8 +588,12 @@ namespace WPEFramework
577588
NULL,
578589
&error))
579590
{
580-
NMLOG_ERROR("client certificate add failed: %s", error->message);
581-
g_error_free(error);
591+
NMLOG_ERROR("client certificate add failed");
592+
if(error != NULL)
593+
{
594+
NMLOG_ERROR("Error message %s", error->message);
595+
g_error_free(error);
596+
}
582597
return false;
583598
}
584599

@@ -589,8 +604,12 @@ namespace WPEFramework
589604
NULL,
590605
&error))
591606
{
592-
NMLOG_ERROR("client private key add failed: %s", error->message);
593-
g_error_free(error);
607+
NMLOG_ERROR("client private key failed");
608+
if(error != NULL)
609+
{
610+
NMLOG_ERROR("Error message %s", error->message);
611+
g_error_free(error);
612+
}
594613
return false;
595614
}
596615

@@ -713,6 +732,9 @@ namespace WPEFramework
713732
NMLOG_ERROR("'%s' connection not found !", knowConnectionID.c_str());
714733
}
715734

735+
if(knownConnection != NULL)
736+
g_object_unref(knownConnection);
737+
716738
deleteClientConnection();
717739
return m_isSuccess;
718740
}
@@ -878,8 +900,10 @@ namespace WPEFramework
878900
ret = nm_remote_connection_update2_finish(remote_con, res, &error);
879901

880902
if (!ret) {
881-
NMLOG_ERROR("Error: %s.", error->message);
882-
g_error_free(error);
903+
if(error) {
904+
NMLOG_ERROR("Error: %s.", error->message);
905+
g_error_free(error);
906+
}
883907
_wifiManager->m_isSuccess = false;
884908
NMLOG_ERROR("AddToKnownSSIDs failed");
885909
}
@@ -995,6 +1019,7 @@ namespace WPEFramework
9951019
{
9961020
NMConnection *m_connection = NULL;
9971021
bool ssidSpecified = false;
1022+
bool connectionFound = false;
9981023

9991024
if(!createClientNewConnection())
10001025
return false;
@@ -1039,13 +1064,27 @@ namespace WPEFramework
10391064
nm_remote_connection_delete(NM_REMOTE_CONNECTION(connection), NULL, &error);
10401065
if(error) {
10411066
NMLOG_ERROR("deleting connection failed %s", error->message);
1067+
g_error_free(error);
1068+
if(m_connection)
1069+
{
1070+
g_object_unref(m_connection);
1071+
m_connection = NULL;
1072+
}
1073+
break; // error break the loop and return false
10421074
}
10431075
else
10441076
NMLOG_INFO("delete '%s' connection ...", connId);
1077+
connectionFound = true;
1078+
}
1079+
1080+
if(m_connection)
1081+
{
1082+
g_object_unref(m_connection);
1083+
m_connection = NULL;
10451084
}
10461085
}
10471086

1048-
if(!m_connection)
1087+
if(!connectionFound)
10491088
{
10501089
if(ssidSpecified)
10511090
NMLOG_WARNING("'%s' no such connection profile", ssid.c_str());
@@ -1054,7 +1093,9 @@ namespace WPEFramework
10541093
}
10551094

10561095
deleteClientConnection();
1057-
return true;
1096+
// ssid is specified and connection is not found return false
1097+
// all other case return true, even if no wificonnection is found
1098+
return((ssidSpecified && !connectionFound)? false : true);
10581099
}
10591100

10601101
bool wifiManager::getKnownSSIDs(std::list<string>& ssids)
@@ -1201,8 +1242,10 @@ namespace WPEFramework
12011242
GMainLoop *loop = static_cast<GMainLoop *>(user_data);
12021243
nm_client_add_and_activate_connection_finish(NM_CLIENT(client), result, &error);
12031244

1204-
if (error)
1245+
if (error) {
12051246
NMLOG_ERROR("Failed to add/activate new connection: %s", error->message);
1247+
g_error_free(error);
1248+
}
12061249
else
12071250
NMLOG_INFO("WPS connection added/activated successfully");
12081251
g_main_loop_quit(loop);
@@ -1236,6 +1279,7 @@ namespace WPEFramework
12361279
nm_remote_connection_delete (NM_REMOTE_CONNECTION(connection), NULL, &error);
12371280
if(error) {
12381281
NMLOG_ERROR("deleting connection failed %s", error->message);
1282+
g_error_free(error);
12391283
return false;
12401284
}
12411285
}
@@ -1526,16 +1570,25 @@ namespace WPEFramework
15261570
wifiManager *_wifiManager = static_cast<wifiManager *>(user_data);
15271571
GError *error = nullptr;
15281572

1529-
if (!nm_client_dbus_set_property_finish(NM_CLIENT(object), result, &error)) {
1530-
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
1573+
if (!nm_client_dbus_set_property_finish(NM_CLIENT(object), result, &error))
1574+
{
1575+
NMLOG_ERROR("Failed to set Managed property");
1576+
if (error != nullptr)
1577+
{
1578+
if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
1579+
{
1580+
NMLOG_ERROR("something went wrong no matching gerror found !");
1581+
}
1582+
else
1583+
{
1584+
NMLOG_ERROR("Failed Error msg: %s", error->message);
1585+
}
15311586
g_error_free(error);
1532-
return;
1587+
_wifiManager->m_isSuccess = false;
15331588
}
1534-
1535-
NMLOG_ERROR("Failed to set Managed property: %s", error->message);
1536-
g_error_free(error);
1537-
_wifiManager->m_isSuccess = false;
1538-
} else {
1589+
}
1590+
else
1591+
{
15391592
NMLOG_DEBUG("Successfully set Managed property.");
15401593
_wifiManager->m_isSuccess = true;
15411594
}
@@ -1664,8 +1717,12 @@ namespace WPEFramework
16641717
NMLOG_DEBUG("activate connection completeing...");
16651718
// Check if the operation was successful
16661719
if (!nm_client_activate_connection_finish(NM_CLIENT(source_object), res, &error)) {
1667-
NMLOG_DEBUG("Activating connection failed: %s", error->message);
1668-
g_error_free(error);
1720+
NMLOG_ERROR("Activating connection failed");
1721+
if(error != NULL)
1722+
{
1723+
NMLOG_ERROR("Activating connection failed: %s", error->message);
1724+
g_error_free(error);
1725+
}
16691726
_wifiManager->m_isSuccess = false;
16701727
} else {
16711728
NMLOG_DEBUG("Activating connection successful");

plugin/gnome/gdbus/NetworkManagerGdbusEvent.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ namespace WPEFramework
4848
GVariant *ifaceVariant = g_dbus_proxy_get_cached_property(deviceProxy, "Interface");
4949
if (ifaceVariant == NULL) {
5050
NMLOG_WARNING("Interface property get error");
51+
g_object_unref(deviceProxy);
5152
return ifname;
5253
}
5354

@@ -750,7 +751,12 @@ namespace WPEFramework
750751

751752
g_variant_get(result, "(ao)", &iter);
752753
if(iter == NULL)
754+
{
755+
NMLOG_ERROR("GetAllAccessPoints GVariantIter returned NULL");
756+
g_variant_unref(result);
757+
g_object_unref(wProxy);
753758
return;
759+
}
754760
while (g_variant_iter_loop(iter, "o", &apPath)) {
755761
Exchange::INetworkManager::WiFiSSIDInfo wifiInfo;
756762
// NMLOG_DEBUG("Access Point Path: %s", apPath);

0 commit comments

Comments
 (0)