pio: close fd when it is not negative number 94/165594/1 accepted/tizen/unified/20180103.151845 submit/tizen/20180103.062104
authorkibak.yoon <kibak.yoon@samsung.com>
Tue, 2 Jan 2018 10:09:04 +0000 (19:09 +0900)
committerkibak.yoon <kibak.yoon@samsung.com>
Tue, 2 Jan 2018 10:09:57 +0000 (19:09 +0900)
Change-Id: I8c6b2f497ce0c519f6dbdb29150edb313b274951
Signed-off-by: kibak.yoon <kibak.yoon@samsung.com>
src/interface/peripheral_interface_gpio.c
src/interface/peripheral_interface_pwm.c

index c71358df95a7ff9f33872b4c7e33b86ee8cf432a..2d792df994057155d57bb247cc2f9f56c3723b27 100644 (file)
@@ -229,9 +229,14 @@ int peripheral_interface_gpio_fd_list_create(int pin, GUnixFDList **list_out)
        *list_out = list;
 
 out:
-       close(fd_direction);
-       close(fd_edge);
-       close(fd_value);
+       if (fd_direction >= 0)
+               close(fd_direction);
+
+       if (fd_edge >= 0)
+               close(fd_edge);
+
+       if (fd_value >= 0)
+               close(fd_value);
 
        return ret;
 }
index c7c5c9552c581ceb0fde6b56677b8c866b5e579f..a7e62c4bde10385fc1b72e325239604265aca5a7 100644 (file)
@@ -221,10 +221,17 @@ int peripheral_interface_pwm_fd_list_create(int chip, int pin, GUnixFDList **lis
        *list_out = list;
 
 out:
-       close(fd_period);
-       close(fd_duty_cycle);
-       close(fd_polarity);
-       close(fd_enable);
+       if (fd_period >= 0)
+               close(fd_period);
+
+       if (fd_duty_cycle >= 0)
+               close(fd_duty_cycle);
+
+       if (fd_polarity >= 0)
+               close(fd_polarity);
+
+       if (fd_enable >= 0)
+               close(fd_enable);
 
        return ret;
 }
@@ -233,4 +240,4 @@ void peripheral_interface_pwm_fd_list_destroy(GUnixFDList *list)
 {
        if (list != NULL)
                g_object_unref(list); // file descriptors in list is closed in hear.
-}
\ No newline at end of file
+}