Fix memory leak
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 15 Mar 2021 01:11:38 +0000 (10:11 +0900)
committer김일호/Tizen Platform Lab(SR)/Engineer/삼성전자 <ilho159.kim@samsung.com>
Mon, 15 Mar 2021 02:34:40 +0000 (11:34 +0900)
free allocated memory by vconf_get_str()

Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/client/pkginfo_client.cc
src/server/runner.cc

index d6824bf..1f353d8 100644 (file)
@@ -160,8 +160,12 @@ bool PkgInfoClient::RequestHandlerDirectAccess() {
   tizen_base::Parcel p;
   p.WriteParcelable(*parcel_.get());
   std::vector<uint8_t> raw = p.GetRaw();
+  char *locale = _get_system_locale();
+  if (locale == nullptr)
+    return false;
 
-  handler->HandleRequest(&raw[0], raw.size(), vconf_get_str(VCONFKEY_LANGSET));
+  handler->HandleRequest(&raw[0], raw.size(), locale);
+  free(locale);
   auto result = handler->GetResult();
   if (result.size() == 0) return true;
 
index 878081a..9320abe 100644 (file)
@@ -22,6 +22,7 @@
 #include "pkg_request.hh"
 #include "runner.hh"
 #include "pkgmgrinfo_debug.h"
+#include "pkgmgrinfo_private.h"
 
 #ifdef LOG_TAG
 #undef LOG_TAG
@@ -37,7 +38,12 @@ Runner::Runner(int thread_num) : sid_(-1), thread_num_(thread_num) {
   thread_pool_ = std::make_unique<WorkerThread>(thread_num_);
   sid_ = g_unix_fd_add(server_->GetFd(), G_IO_IN, OnReceiveRequest, this);
   vconf_notify_key_changed(VCONFKEY_LANGSET, OnLanguageChange, this);
-  thread_pool_->SetLocale(vconf_get_str(VCONFKEY_LANGSET));
+  char *locale = _get_system_locale();
+  if (locale == nullptr)
+    return;
+
+  thread_pool_->SetLocale(locale);
+  free(locale);
   LOGI("Start Runner");
 }
 
@@ -78,7 +84,12 @@ int Runner::OnReceiveRequest(int fd, GIOCondition cond, void* user_data) {
 
 void Runner::OnLanguageChange(keynode_t* key, void* user_data) {
   auto runner = static_cast<Runner*>(user_data);
-  runner->thread_pool_->SetLocale(vconf_get_str(VCONFKEY_LANGSET));
+  char *locale = _get_system_locale();
+  if (locale == nullptr)
+    return;
+
+  runner->thread_pool_->SetLocale(locale);
+  free(locale);
 }
 
 bool Runner::QueueRequest(int client_fd) {