[ML][Pipeline][Single] Fix SVACE issues 11/254911/4
authorPawel Wasowski <p.wasowski2@samsung.com>
Wed, 10 Mar 2021 10:31:04 +0000 (11:31 +0100)
committerPawel Wasowski <p.wasowski2@samsung.com>
Wed, 10 Mar 2021 11:11:18 +0000 (11:11 +0000)
This commit fixes the following issues reported on
analysishub.sec.samsung.net (WGIDs):
- 457566
- 457567
- 457568

[Verification] Code compiles. SVACE analysis after
applying the patch
(https://analysishub.sec.samsung.net/service/analyses/394936)
found no errors.

CustomFilter tested in Chrome DevTools with the
snippet below works fine

// Valid CustomFilter callback - the happy scenario
var inputTI = new tizen.ml.TensorsInfo();
inputTI.addTensorInfo('ti1', 'UINT8', [4, 20, 15, 1]);
var outputTI = new tizen.ml.TensorsInfo();
outputTI.addTensorInfo('ti1', 'UINT8', [1200]);
var flattenAndSet123 = function(input, output) {
    console.log("Custom filter called");

    var rawOutputData = new Uint8Array(1200);
    for (var i = 0; i < rawOutputData.length; ++i) {
        rawOutputData[i] = 123;
    }

    output.setTensorRawData(0, rawOutputData);
    return 0;
}

tizen.ml.pipeline.registerCustomFilter('testfilter2', flattenAndSet123, inputTI,
    outputTI, function errorCallback(error) {
        console.warn('custom filter error:') ; console.warn(error);
    });

var pipeline_def = "videotestsrc num-buffers=3 "
                   + "! video/x-raw,width=20,height=15,format=BGRA "
                   + "! tensor_converter "
                   + "! tensor_filter framework=custom-easy model=testfilter2 "
                   + "! appsink name=mysink";

var pipeline = tizen.ml.pipeline.createPipeline(pipeline_def,
                                                state => {console.log(state);})

pipeline.registerSinkListener('mysink', function(sinkName, data) {
    console.log('SinkListener for "' + sinkName + '" sink called');
    console.log(data);
})

// READY
// Custom filter called
// PAUSED

pipeline.start()

// PLAYING
// <CustomFilter and SinkListener callbacks' outputs 3 times>

Change-Id: Id1d35167532c3aeecbd3c73c3546b80e31e8f76c
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
src/ml/ml_pipeline_custom_filter.cc
src/ml/ml_singleshot.cc

index 8373d9b..fc54c93 100644 (file)
@@ -197,7 +197,7 @@ bool CustomFilter::PrepareMessageWithInputData(
 
   *input_tensors_data_ptr = tensors_data_manager_ptr_->CreateTensorsData(
       input_tensors_info_ptr_, native_input_tensors_data_handle, false, true);
-  if (!input_tensors_data_ptr) {
+  if (!(*input_tensors_data_ptr)) {
     LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal CustomFilter error"),
                       &message_obj,
                       ("Could not create TensorsData. Custom filter won't be triggered."));
@@ -206,7 +206,7 @@ bool CustomFilter::PrepareMessageWithInputData(
 
   *output_tensors_data_ptr = tensors_data_manager_ptr_->CreateTensorsData(
       output_tensors_info_ptr_, native_output_tensors_data_handle, false, false);
-  if (!output_tensors_data_ptr) {
+  if (!(*output_tensors_data_ptr)) {
     LogAndReportError(PlatformResult(ErrorCode::ABORT_ERR, "Internal CustomFilter error"),
                       &message_obj,
                       ("Could not create TensorsData. Custom filter won't be triggered."));
index ad7b68f..5bfb9e3 100644 (file)
@@ -37,9 +37,15 @@ SingleShot::SingleShot(int id, ml_single_h handle, bool dynamic_mode)
 
 // 'this' owns a handle_, and invalidates 'o'
 SingleShot::SingleShot(SingleShot&& o)
-    : id_(o.id_), handle_(o.handle_), dynamic_mode_(o.dynamic_mode_) {
+    : id_(o.id_),
+      handle_(o.handle_),
+      dynamic_mode_(o.dynamic_mode_),
+      tensor_data_out_handle_(o.tensor_data_out_handle_),
+      tensor_info_out_handle_(o.tensor_info_out_handle_) {
   ScopeLogger("id: %d", id_);
   o.handle_ = nullptr;
+  o.tensor_data_out_handle_ = nullptr;
+  o.tensor_info_out_handle_ = nullptr;
 }
 
 SingleShot::~SingleShot() {