[Coverity] Fix Coverity issue at neuralnet destructor
authorDonghak PARK <donghak.park@samsung.com>
Thu, 6 Feb 2025 01:26:10 +0000 (10:26 +0900)
committerjijoong.moon <jijoong.moon@samsung.com>
Fri, 7 Feb 2025 02:15:08 +0000 (11:15 +0900)
Uncaught exception (UNCAUGHT_EXCEPT)

exn_spec_violation: An exception of type std::length_error is thrown but the exception specification /*implicit*/noexcept doesn't allow it to be thrown. This will result in a call to terminate().
- in general, throw exception at destrctor is not allowed
- so, add exception at deallocate Tensor

Resolves:

**Self evaluation:**
1. Build test:  [X]Passed [ ]Failed [ ]Skipped
2. Run test:  [X]Passed [ ]Failed [ ]Skipped

Signed-off-by: Donghak PARK <donghak.park@samsung.com>
nntrainer/models/neuralnet.cpp

index d0e542825fa736265938cb0ae042c07fd3415227..0abf3ab1785ff8a7845ebd02199ba16529a4c861 100644 (file)
@@ -892,9 +892,14 @@ int NeuralNetwork::allocate(ExecutionMode mode) {
 }
 
 int NeuralNetwork::deallocate() {
-  model_graph.deallocateTensors(true);
-
-  return ML_ERROR_NONE;
+  try {
+    model_graph.deallocateTensors(true);
+    return ML_ERROR_NONE;
+  } catch (const std::exception &e) {
+    std::cerr << "Error occurred during deallocation of NeuralNetwork: "
+              << e.what() << std::endl;
+    return ML_ERROR_UNKNOWN;
+  }
 }
 
 int NeuralNetwork::train(const std::vector<std::string> &values,