keystore/file: fix error path
authorThomas Guillem <thomas@gllm.fr>
Tue, 12 Apr 2016 15:33:07 +0000 (17:33 +0200)
committerThomas Guillem <thomas@gllm.fr>
Tue, 12 Apr 2016 15:35:45 +0000 (17:35 +0200)
modules/keystore/file.c

index 3c7a75b..0c3f7bb 100644 (file)
@@ -296,17 +296,22 @@ file_open(const char *psz_file, const char *psz_mode, FILE **pp_file)
 
     int i_fd = fileno(p_file);
     if (i_fd == -1)
+    {
+        fclose(p_file);
         return -1;
+    }
 
 #ifdef HAVE_FLOCK
     if (flock(i_fd, LOCK_EX) != 0)
     {
         fclose(p_file);
+        return -1;
     }
 #elif defined (HAVE_FCNTL) && defined (F_SETLKW)
     if (posix_lock_fd(i_fd) != 0)
     {
         fclose(p_file);
+        return -1;
     }
 #endif
     *pp_file = p_file;