Use unique_ptr at allocated char*
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 15 Mar 2021 02:29:49 +0000 (11:29 +0900)
committer김일호/Tizen Platform Lab(SR)/Engineer/삼성전자 <ilho159.kim@samsung.com>
Mon, 15 Mar 2021 02:34:40 +0000 (11:34 +0900)
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/client/pkginfo_client.cc
src/server/runner.cc

index 661317178b3352fa502fdbf3ec86d8e621c8833e..d52f601a09ce0b6f3b939c503280bd62ae20eb46 100644 (file)
@@ -160,12 +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)
+  std::unique_ptr<char, decltype(std::free)*> locale(
+      _get_system_locale(), std::free);
+  if (locale.get() == nullptr)
     return false;
 
-  handler->HandleRequest(&raw[0], raw.size(), locale);
-  free(locale);
+  handler->HandleRequest(&raw[0], raw.size(), locale.get());
   auto result = handler->ExtractResult();
   if (result.size() == 0) return true;
 
index 9320abed0e5a046f32f49b705121fe3ab9067236..604d1f27799f7d5e3b0799816f7a2004250367ac 100644 (file)
@@ -38,12 +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);
-  char *locale = _get_system_locale();
-  if (locale == nullptr)
+  std::unique_ptr<char, decltype(std::free)*> locale(
+      _get_system_locale(), std::free);
+  if (locale.get() == nullptr)
     return;
 
-  thread_pool_->SetLocale(locale);
-  free(locale);
+  thread_pool_->SetLocale(locale.get());
   LOGI("Start Runner");
 }
 
@@ -84,12 +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);
-  char *locale = _get_system_locale();
-  if (locale == nullptr)
+  std::unique_ptr<char, decltype(std::free)*> locale(
+      _get_system_locale(), std::free);
+  if (locale.get() == nullptr)
     return;
 
-  runner->thread_pool_->SetLocale(locale);
-  free(locale);
+  runner->thread_pool_->SetLocale(locale.get());
 }
 
 bool Runner::QueueRequest(int client_fd) {