Fix static analysis issue 66/211766/6
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 9 Aug 2019 04:12:40 +0000 (13:12 +0900)
committerilho kim <ilho159.kim@samsung.com>
Tue, 13 Aug 2019 04:02:02 +0000 (04:02 +0000)
Fix NULL Pointer dereference when memory allocation fails

Change-Id: If23103d7135852ba98cc52173982cdc5bca47ca0
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/common/pkgmgr_registration.cc
src/common/step/pkgmgr/step_check_force_clean.cc

index 5331360..fc67aa0 100644 (file)
@@ -173,6 +173,10 @@ bool UnregisterAppInPkgmgrForPkgId(const std::string& pkgid, uid_t uid,
                                    RequestMode request_mode) {
   manifest_x* manifest =
      static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
+  if (!manifest) {
+    LOG(ERROR) << "Out of memory";
+    return false;
+  }
   PkgmgrGenerateManifestInfoFromDB(manifest, pkgid, uid);
   bool res = UnregisterAppInPkgmgr(manifest, pkgid, uid, request_mode);
   pkgmgr_parser_free_manifest_xml(manifest);
index 5490324..bc29170 100644 (file)
@@ -37,6 +37,10 @@ Step::Status StepCheckForceClean::process() {
     context_->force_clean_from_db.set(true);
     manifest_x* manifest =
         static_cast<manifest_x*>(calloc(1, sizeof(manifest_x)));
+    if (!manifest) {
+      LOG(ERROR) << "Out of memory";
+      return Status::ERROR;
+    }
     if (!PkgmgrGenerateManifestInfoFromDB(manifest, context_->pkgid.get(),
             context_->uid.get())) {
       context_->manifest_data.set(manifest);