atrace: Fix a svace issue 94/313994/1 accepted/tizen_unified_dev accepted/tizen/unified/20240704.173826 accepted/tizen/unified/dev/20240708.001750 accepted/tizen/unified/toolchain/20240812.131449 accepted/tizen/unified/x/20240705.012351 accepted/tizen/unified/x/asan/20240813.225725
authorSung-hun Kim <sfoon.kim@samsung.com>
Thu, 4 Jul 2024 01:04:59 +0000 (10:04 +0900)
committerSung-hun Kim <sfoon.kim@samsung.com>
Thu, 4 Jul 2024 01:04:59 +0000 (10:04 +0900)
The new operator in C++ does not return nullptr when it is failed.
Instead, it throws a bad_alloc exception to notify the failure.
With an optional `std::nothrow` keyword, the new operator returns
nullptr instead of exception throwing when it is failed.

This patch fixes a svace issue 209972.

Change-Id: I6a6f900f06bf7911fc9aa53366d5da6375680915
Signed-off-by: Sung-hun Kim <sfoon.kim@samsung.com>
atrace/atrace.cpp

index a465be0494001bdf99ded184f3d2258d397e40d7..4d068452fb8ad5224eeb1e78ccea3c30263a7761 100755 (executable)
@@ -757,8 +757,8 @@ static void dumpTrace(bool startup)
         }
 
         const size_t bufSize = 64*1024;
-        std::unique_ptr<uint8_t[]> in(new uint8_t[bufSize]);
-        std::unique_ptr<uint8_t[]> out(new uint8_t[bufSize]);
+        std::unique_ptr<uint8_t[]> in(new(std::nothrow) uint8_t[bufSize]);
+        std::unique_ptr<uint8_t[]> out(new(std::nothrow) uint8_t[bufSize]);
         if ((in == nullptr) || (out == nullptr)) {
             fprintf(stderr, "Could not allocate memory");
             close(traceFD);