bootstrap: Fix resource leak issue in InstallAppCommand 64/270664/2
authorWoochanlee <wc0917.lee@samsung.com>
Mon, 7 Feb 2022 11:10:09 +0000 (20:10 +0900)
committerwoochan lee <wc0917.lee@samsung.com>
Thu, 10 Feb 2022 02:43:11 +0000 (02:43 +0000)
pkgRequest alloc in create and it has to free before end of function scope.

Change-Id: I753fcf1f9c3c911daa3ae108220f38fa22160dcd

org.tizen.aurum-bootstrap/src/Commands/InstallAppCommand.cc

index 3f9d5da5ede7acd86fe6ecccd6beb3553522d9b0..10747f3224744ce1ea55680bbd580080531b2a06 100644 (file)
@@ -47,10 +47,27 @@ InstallAppCommand::InstallAppCommand(
     package_manager_request_h pkgRequest;
     int                       id;
 
-    package_manager_request_create(&pkgRequest);
-    package_manager_request_install(pkgRequest, "/tmp/app.tpk", &id);
+    if (package_manager_request_create(&pkgRequest) != PACKAGE_MANAGER_ERROR_NONE) {
+        LOGE("Could not create install request. App: %s", chunk.package().c_str());
+        return grpc::Status::CANCELLED;;
+    }
+    if (package_manager_request_install(pkgRequest, "/tmp/app.tpk", &id) != PACKAGE_MANAGER_ERROR_NONE) {
+        LOGE("Could not install application. App: %s", chunk.package().c_str());
+        goto END;
+    }
+    if (package_manager_request_destroy(pkgRequest) != PACKAGE_MANAGER_ERROR_NONE) {
+        pkgRequest = NULL;
+        LOGE("Could not destroy install request. App: %s", chunk.package().c_str());
+        goto END;
+    }
 
     return grpc::Status::OK;
+
+END:
+    if (pkgRequest != NULL)
+        package_manager_request_destroy(pkgRequest);
+
+    return grpc::Status::CANCELLED;
 }
 
 ::grpc::Status InstallAppCommand::executePost()