Whamcloud - gitweb
LU-7936 utils: fix resource lost 93/19193/5
authorDmitry Eremin <dmitry.eremin@intel.com>
Tue, 29 Mar 2016 14:33:48 +0000 (17:33 +0300)
committerOleg Drokin <oleg.drokin@intel.com>
Mon, 11 Apr 2016 02:52:10 +0000 (02:52 +0000)
Close file handle before return from function.

Change-Id: I1cea4c1d60672b945cd524367e91fb27df185c87
Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
Reviewed-on: http://review.whamcloud.com/19193
Tested-by: Jenkins
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/liblustreapi_hsm.c

index d95383a..95ac6da 100644 (file)
@@ -472,6 +472,7 @@ out_free:
  */
 int llapi_hsm_register_event_fifo(const char *path)
 {
+       int rc;
        int read_fd;
        struct stat statbuf;
 
@@ -508,17 +509,19 @@ int llapi_hsm_register_event_fifo(const char *path)
        /* Open the FIFO for writes, but don't block on waiting
         * for a reader. */
        llapi_hsm_event_fd = open(path, O_WRONLY | O_NONBLOCK);
-       if (llapi_hsm_event_fd < 0) {
-               llapi_error(LLAPI_MSG_ERROR, errno,
-                           "cannot open(%s) for write", path);
-               return -errno;
-       }
+       rc = -errno;
 
        /* Now close the reader. An external monitoring process can
         * now open the FIFO for reads. If no reader comes along the
         * events are lost. NOTE: Only one reader at a time! */
        close(read_fd);
 
+       if (llapi_hsm_event_fd < 0) {
+               llapi_error(LLAPI_MSG_ERROR, -rc,
+                           "cannot open(%s) for write", path);
+               return rc;
+       }
+
        /* Ignore SIGPIPEs -- can occur if the reader goes away. */
        signal(SIGPIPE, SIG_IGN);