diff options
author | Junghoon Park <jh9216.park@samsung.com> | 2020-07-20 13:51:32 +0900 |
---|---|---|
committer | Junghoon Park <jh9216.park@samsung.com> | 2020-07-22 10:35:29 +0900 |
commit | 54a2839519058c8fb8bb847dcdab084d6fd82f5c (patch) | |
tree | 0b7914f894c542ae081f8bd2039750ac674330c5 | |
parent | 779f927e52cec301cdb608fd1742ef63a763dcc5 (diff) | |
download | notification-54a2839519058c8fb8bb847dcdab084d6fd82f5c.tar.gz notification-54a2839519058c8fb8bb847dcdab084d6fd82f5c.tar.bz2 notification-54a2839519058c8fb8bb847dcdab084d6fd82f5c.zip |
Fix memory leak
- Remove useless invocations of strdup()
- Change g_variant argument types to reference type
Change-Id: I80f7bd057440023d1127bec34d4bcd9456364621
Signed-off-by: Junghoon Park <jh9216.park@samsung.com>
-rw-r--r-- | notification-ex/dbus_event_listener.cc | 26 | ||||
-rw-r--r-- | notification-ex/shared_file.cc | 12 |
2 files changed, 20 insertions, 18 deletions
diff --git a/notification-ex/dbus_event_listener.cc b/notification-ex/dbus_event_listener.cc index a075622..e37a3a2 100644 --- a/notification-ex/dbus_event_listener.cc +++ b/notification-ex/dbus_event_listener.cc @@ -172,28 +172,33 @@ void DBusEventListener::Impl::SignalCb(GDBusConnection* connection, char* appid = nullptr; GVariantIter *iter = nullptr; char* event_info_raw = nullptr; - g_variant_get(parameters, "(ssa(s))", &appid, &event_info_raw, &iter); + g_variant_get(parameters, "(&s&sa(s))", &appid, &event_info_raw, &iter); LOGI("signal callback!! (%s)", appid); string sender_appid = string(appid); string cur_appid = util::GetAppId(); - if (sender_appid == cur_appid) + if (sender_appid == cur_appid) { + g_variant_iter_free(iter); return; + } if ((!DBusConnectionManager::GetInst().IsDataProviderMaster(cur_appid) && !DBusConnectionManager::GetInst().IsDataProviderMaster(sender_appid)) - || (cur_appid == sender_appid)) + || (cur_appid == sender_appid)) { + g_variant_iter_free(iter); return; + } LOGD("%s : %s", cur_appid.c_str(), sender_appid.c_str()); try { char* raw = nullptr; list<Bundle> ret_list; - while (g_variant_iter_loop(iter, "(s)", &raw) && raw != nullptr) { + while (g_variant_iter_loop(iter, "(&s)", &raw) && raw != nullptr) { Bundle ret(raw); ret_list.emplace_back(ret); } + g_variant_iter_free(iter); Bundle b(event_info_raw); EventInfo info(b); if (info.GetEventType() == EventInfo::Post @@ -217,28 +222,33 @@ void DBusEventListener::Impl::MethodCallHandler(GVariant* parameters, GVariantIter* iter = nullptr; char* event_info_raw = nullptr; - g_variant_get(parameters, "(ssa(s))", &appid, &event_info_raw, &iter); + g_variant_get(parameters, "(&s&sa(s))", &appid, &event_info_raw, &iter); string sender_appid = string(appid); string cur_appid = util::GetAppId(); LOGI("MethodCallHandler!! appid(%s), sender(%s), cur(%s)", appid, sender_appid.c_str(), cur_appid.c_str()); - if (sender_appid == cur_appid) + if (sender_appid == cur_appid) { + g_variant_iter_free(iter); return; + } if ((!DBusConnectionManager::GetInst().IsDataProviderMaster(cur_appid) && !DBusConnectionManager::GetInst().IsDataProviderMaster(sender_appid)) - || (cur_appid == sender_appid)) + || (cur_appid == sender_appid)) { + g_variant_iter_free(iter); return; + } char* raw = nullptr; list<Bundle> ret_list; - while (g_variant_iter_loop(iter, "(s)", &raw) && raw != nullptr) { + while (g_variant_iter_loop(iter, "(&s)", &raw) && raw != nullptr) { Bundle ret(raw); ret_list.emplace_back(ret); } + g_variant_iter_free(iter); Bundle b(event_info_raw); EventInfo info(b); diff --git a/notification-ex/shared_file.cc b/notification-ex/shared_file.cc index d630a73..c860fd1 100644 --- a/notification-ex/shared_file.cc +++ b/notification-ex/shared_file.cc @@ -248,11 +248,7 @@ int SharedFile::SetSharingData(SharingData sharing_data, if (req == nullptr) return ERROR_IO_ERROR; - appid = strdup(sharing_data.app_id.c_str()); - if (appid == nullptr) { - LOGE("Failed to get Sender appid"); - return ERROR_OUT_OF_MEMORY; - } + appid = sharing_data.app_id.c_str(); ret = security_manager_private_sharing_req_set_owner_appid(req.get(), appid); if (ret != SECURITY_MANAGER_SUCCESS) { @@ -327,11 +323,7 @@ int SharedFile::UnsetSharingData(SharingData sharing_data, if (req == nullptr) return ERROR_IO_ERROR; - appid = strdup(sharing_data.app_id.c_str()); - if (appid == nullptr) { - LOGE("Failed to get Sender appid"); - return ERROR_OUT_OF_MEMORY; - } + appid = sharing_data.app_id.c_str(); ret = security_manager_private_sharing_req_set_owner_appid(req.get(), appid); if (ret != SECURITY_MANAGER_SUCCESS) { |