mv3d: fix bugs
authorTae-Young Chung <ty83.chung@samsung.com>
Thu, 22 Sep 2022 05:24:48 +0000 (14:24 +0900)
committerTae-Young Chung <ty83.chung@samsung.com>
Thu, 22 Sep 2022 06:06:57 +0000 (15:06 +0900)
[Issue type] : bug fix (SVACE: WGID 499255,499256,499263,499267)

499255: fix flcose() with nullptr
499256: fix delete operation with malloc()
499263: fix assignment of a signed integer value to a bigger size_t
499267: fix memory leak of suffix_for_algo

Change-Id: I415baa95286527007e3b8aff8befd218ebe0a09b
Signed-off-by: Tae-Young Chung <ty83.chung@samsung.com>
mv_3d/3d/include/Mv3d.h
mv_3d/3d/src/Mv3d.cpp
mv_3d/3d/src/mv_3d_open.cpp
test/testsuites/mv3d/depth_test_suite.cpp
test/testsuites/mv3d/depthstream_test_suite.cpp

index 8f3558c54dfdec2e7aac89826fe1cafbc1fc53ac..3614cea1e4e921488a3cacdb0babcb7a87fc7993 100644 (file)
@@ -47,8 +47,8 @@ namespace mv3d
 
                size_t mWidth;
                size_t mHeight;
-               size_t mMinDisp;
-               size_t mMaxDisp;
+               int mMinDisp;
+               int mMaxDisp;
                double mSamplingRatio;
                int mOutlierRemovalPoints;
                double mOutlierRemovalRadius;
index dc4c05c47c39010d48651276b4fdafbd27f4fb0d..258307afb5122649c8d1a6ddacdb37e1399fdb46 100644 (file)
@@ -104,8 +104,8 @@ namespace mv3d
                                                std::string pointcloudOutputPath)
        {
                mMode = mode;
-               mWidth = width;
-               mHeight = height;
+               mWidth = static_cast<size_t>(width);
+               mHeight = static_cast<size_t>(height);
                mMinDisp = minDisp;
                mMaxDisp = maxDisp;
                mSamplingRatio = samplingRatio;
index 72021a2ca29448716c3b8f7406642f76cf8915a5..24d2189aaf85c2bcf5098335998cebe1763faf9b 100644 (file)
@@ -115,6 +115,11 @@ int mv3dConfigure(mv_3d_h mv3d, mv_engine_config_h engine_config)
                return ret;
        }
 
+       if (depthWidth <= 0 || depthHeight <= 0) {
+               LOGE("Invalid depth resolution %d x %d", depthWidth, depthHeight);
+               return MEDIA_VISION_ERROR_INVALID_PARAMETER;
+       }
+
        ret = mv_engine_config_get_int_attribute(
                        engine_config, MV_3D_DEPTH_MIN_DISPARITY, &minDisp);
        if (ret != MEDIA_VISION_ERROR_NONE) {
index 26997e5f3673e29008215a1effb1a0f6dd76d5c3..bee220178b9b996df0eca67ec9250d9719e9de73 100644 (file)
@@ -338,8 +338,11 @@ int perform_middlebury_test()
                                if (sscanf(line, "width= %d", &iVal) == 1) width = iVal;
                                if (sscanf(line, "height= %d", &iVal) == 1) height = iVal;
                        }
+                       fclose(fp);
+               } else {
+                       printf("Fail to open %s\n", calibFilename);
+                       goto _err;
                }
-               fclose(fp);
 
                int minDisp = static_cast<int>(dmin);
                int maxDisp = static_cast<int>(dmax);
@@ -507,6 +510,9 @@ _err:
        if (path_to_dataset)
                free(path_to_dataset);
 
+       if (suffix_for_algo)
+               free(suffix_for_algo);
+
        if (engine_config)
                mv_destroy_engine_config(engine_config);
 
index c8241b97698391c98ecac3464b0aa0fffbbea9e3..16a4d4ebbee5746c26f4297fae4409cd34f5914d 100644 (file)
@@ -265,7 +265,7 @@ void _depth_stereo_cb(mv_source_h source, unsigned short *depth, unsigned int wi
        camera::PinholeCameraIntrinsic intrinsic;
        io::ReadIJsonConvertible(INTRINSIC_FILE_PATH, intrinsic);
 
-       vertex3d = (float *)malloc(width * height * 4);
+       vertex3d = new float[width * height * 4];
        memset(vertex3d, 0, width * height * 4);
        utility::LogInfo("focal_x = {}", intrinsic.GetFocalLength().first);
        utility::LogInfo("focal_y = {}", intrinsic.GetFocalLength().second);