[Security] handle return value
authorJaeyun <jy1210.jung@samsung.com>
Wed, 25 Sep 2019 08:17:19 +0000 (17:17 +0900)
committerMyungJoo Ham <myungjoo.ham@samsung.com>
Wed, 25 Sep 2019 10:24:57 +0000 (19:24 +0900)
Fix svace issues, check returned value and file descriptor.

Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
api/capi/src/nnstreamer-capi-single-new.c
tests/nnstreamer_source/unittest_src_iio.cpp

index fbc48c2..fd01a72 100644 (file)
@@ -694,7 +694,7 @@ ml_single_get_output_info (ml_single_h single, ml_tensors_info_h * info)
   }
 
   g_object_get (single_h->filter, "outputname", &val, NULL);
-  gst_tensors_info_parse_names_string (&gst_info, val);
+  rank = gst_tensors_info_parse_names_string (&gst_info, val);
   g_free (val);
 
   if (gst_info.num_tensors != rank) {
index be05962..383a551 100644 (file)
@@ -142,7 +142,7 @@ make_iio_dev_structure (int num)
   const gchar *_tmp_dir = g_get_tmp_dir ();
   const gchar *_dirname = "nnst-src-XXXXXX";
 
-  iio_dev_dir_struct *iio_dev = g_new (iio_dev_dir_struct, 1);
+  iio_dev_dir_struct *iio_dev = g_new0 (iio_dev_dir_struct, 1);
   iio_dev->base_dir = g_build_filename (_tmp_dir, _dirname, NULL);
   iio_dev->base_dir = g_mkdtemp_full (iio_dev->base_dir, 0777);
   EXPECT_EQ (safe_rmdir (iio_dev->base_dir), 0);
@@ -216,6 +216,8 @@ make_iio_dev_structure (int num)
       g_build_filename (iio_dev->dev_dir, device_folder_name, NULL);
 
   iio_dev->log_file = NULL;
+  iio_dev->dev_device_dir_fd = -1;
+  iio_dev->dev_device_dir_fd_read = -1;
 
   PREV_IIO_DEV_DIR = IIO_DEV_DIR;
   IIO_DEV_DIR = g_strdup (iio_dev->dev_dir);
@@ -772,8 +774,10 @@ destroy_dev_dir (const iio_dev_dir_struct * iio_dev)
   status += safe_rmdir (iio_dev->bus_dir);
   status += safe_rmdir (iio_dev->sys_dir);
 
-  close (iio_dev->dev_device_dir_fd);
-  close (iio_dev->dev_device_dir_fd_read);
+  if (iio_dev->dev_device_dir_fd >= 0)
+    close (iio_dev->dev_device_dir_fd);
+  if (iio_dev->dev_device_dir_fd_read >= 0)
+    close (iio_dev->dev_device_dir_fd_read);
   status += safe_remove (iio_dev->dev_device_dir);
   status += safe_rmdir (iio_dev->dev_dir);
   if (iio_dev->log_file != NULL) {