From 71e11e97c0f7da37cd34424ec25058a073ad085f Mon Sep 17 00:00:00 2001 From: Kazumasa Mitsunari Date: Fri, 14 Sep 2018 20:05:11 +0900 Subject: Fix memory leak of return value of afb_req_get_application_id Change-Id: I522e6e77ee76d44136c4398a1d67ce66a5b71638 Signed-off-by: Kazumasa Mitsunari --- src/main.cpp | 140 ++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 85 insertions(+), 55 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b0c9415..964abde 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include "window_manager.hpp" #include "json_helper.hpp" @@ -143,18 +144,26 @@ void windowmanager_requestsurface(afb_req req) noexcept return; } - const char *appid = afb_req_get_application_id(req); - auto ret = g_afb_instance->wmgr.api_request_surface( - appid, a_drawing_name); - if (ret.is_err()) + char *appid = afb_req_get_application_id(req); + if(appid) { - afb_req_fail(req, "failed", ret.unwrap_err()); - return; + auto ret = g_afb_instance->wmgr.api_request_surface( + appid, a_drawing_name); + if (ret.is_err()) + { + afb_req_fail(req, "failed", ret.unwrap_err()); + } + else + { + createSecurityContext(req, appid, a_drawing_name); + afb_req_success(req, json_object_new_int(ret.unwrap()), "success"); + } + free(appid); + } + else + { + afb_req_fail(req, "failed", nullptr); } - - createSecurityContext(req, appid, a_drawing_name); - - afb_req_success(req, json_object_new_int(ret.unwrap()), "success"); } catch (std::exception &e) { @@ -192,19 +201,23 @@ void windowmanager_requestsurfacexdg(afb_req req) noexcept return; } char const *a_ivi_id = json_object_get_string(j_ivi_id); - char const *appid = afb_req_get_application_id(req); - auto ret = g_afb_instance->wmgr.api_request_surface( - appid, a_drawing_name, a_ivi_id); - - if (ret != nullptr) + char *appid = afb_req_get_application_id(req); + if(appid) { - afb_req_fail(req, "failed", ret); - return; + auto ret = g_afb_instance->wmgr.api_request_surface( + appid, a_drawing_name, a_ivi_id); + + if (ret != nullptr) + { + afb_req_fail(req, "failed", ret); + } + else + { + createSecurityContext(req, appid, a_drawing_name); + afb_req_success(req, NULL, "success"); + } + free(appid); } - - createSecurityContext(req, appid, a_drawing_name); - - afb_req_success(req, NULL, "success"); } catch (std::exception &e) { @@ -223,7 +236,6 @@ void windowmanager_setrole(afb_req req) noexcept } try { - char const *appid = afb_req_get_application_id(req); json_object *jreq = afb_req_json(req); json_object *j_role = nullptr; @@ -233,17 +245,22 @@ void windowmanager_setrole(afb_req req) noexcept return; } char const *a_role = json_object_get_string(j_role); + char *appid = afb_req_get_application_id(req); - auto ret = g_afb_instance->wmgr.api_set_role(appid, a_role); - if (!ret) + if(appid) { - afb_req_fail(req, "failed", "Couldn't register"); - return; + auto ret = g_afb_instance->wmgr.api_set_role(appid, a_role); + if (!ret) + { + afb_req_fail(req, "failed", "Couldn't register"); + } + else + { + createSecurityContext(req, appid, a_role); + afb_req_success(req, NULL, "success"); + } + free(appid); } - - createSecurityContext(req, appid, a_role); - - afb_req_success(req, NULL, "success"); } catch (std::exception &e) { @@ -278,18 +295,22 @@ void windowmanager_activatewindow(afb_req req) noexcept return; } - g_afb_instance->wmgr.api_activate_surface( - afb_req_get_application_id(req), - a_drawing_name, a_drawing_area, - [&req](const char *errmsg) { - if (errmsg != nullptr) - { - HMI_ERROR(errmsg); - afb_req_fail(req, "failed", errmsg); - return; - } - afb_req_success(req, NULL, "success"); - }); + char* appid = afb_req_get_application_id(req); + if(appid) + { + g_afb_instance->wmgr.api_activate_surface( + appid, a_drawing_name, a_drawing_area, + [&req](const char *errmsg) { + if (errmsg != nullptr) + { + HMI_ERROR(errmsg); + afb_req_fail(req, "failed", errmsg); + return; + } + afb_req_success(req, NULL, "success"); + }); + free(appid); + } } catch (std::exception &e) { @@ -318,17 +339,22 @@ void windowmanager_deactivatewindow(afb_req req) noexcept return; } - g_afb_instance->wmgr.api_deactivate_surface( - afb_req_get_application_id(req), a_drawing_name, - [&req](const char *errmsg) { - if (errmsg != nullptr) - { - HMI_ERROR(errmsg); - afb_req_fail(req, "failed", errmsg); - return; - } - afb_req_success(req, NULL, "success"); - }); + char* appid = afb_req_get_application_id(req); + if(appid) + { + g_afb_instance->wmgr.api_deactivate_surface( + appid, a_drawing_name, + [&req](const char *errmsg) { + if (errmsg != nullptr) + { + HMI_ERROR(errmsg); + afb_req_fail(req, "failed", errmsg); + return; + } + afb_req_success(req, NULL, "success"); + }); + free(appid); + } } catch (std::exception &e) { @@ -358,8 +384,12 @@ void windowmanager_enddraw(afb_req req) noexcept } afb_req_success(req, NULL, "success"); - g_afb_instance->wmgr.api_enddraw( - afb_req_get_application_id(req), a_drawing_name); + char* appid = afb_req_get_application_id(req); + if(appid) + { + g_afb_instance->wmgr.api_enddraw(appid, a_drawing_name); + free(appid); + } } catch (std::exception &e) { -- cgit 1.2.3-korg