Whamcloud - gitweb
LU-4629 utils: fix rsources leak 43/9343/3
authorDmitry Eremin <dmitry.eremin@intel.com>
Fri, 21 Feb 2014 12:33:30 +0000 (16:33 +0400)
committerOleg Drokin <oleg.drokin@intel.com>
Sat, 1 Mar 2014 02:25:11 +0000 (02:25 +0000)
Resource acquired to 'fp' at line 3540 may be lost here.
Resource acquired to 'debug_log' at line 1690 may be lost here.
Resource acquired to 'mattr' at line 471 may be lost here.
Resource acquired to 'conn->oc_fd' at line 208 may be lost here.

Signed-off-by: Dmitry Eremin <dmitry.eremin@intel.com>
Change-Id: I47a1c44d8b1cfd8500ca71958814b8a23d6fff2b
Reviewed-on: http://review.whamcloud.com/9343
Tested-by: Jenkins
Reviewed-by: John L. Hammond <john.hammond@intel.com>
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Nunez <james.a.nunez@intel.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/utils/lfs.c
lustre/utils/lustre_rsync.c
lustre/utils/obd.c
lustre/utils/obdbarrier.c

index 5af9305..ef03636 100644 (file)
@@ -3713,6 +3713,7 @@ static int lfs_hsm_request(int argc, char **argv, int action)
                                                strerror(errno));
                                        hur = oldhur;
                                        rc = -errno;
+                                       fclose(fp);
                                        goto out_free;
                                }
                                memcpy(hur, oldhur, hur_len(oldhur));
@@ -3729,8 +3730,10 @@ static int lfs_hsm_request(int argc, char **argv, int action)
                        rc = lfs_hsm_prepare_file(line, &hui->hui_fid,
                                                  &last_dev);
                        hur->hur_request.hr_itemcount++;
-                       if (rc)
+                       if (rc) {
+                               fclose(fp);
                                goto out_free;
+                       }
 
                        if ((some_file[0] == '\0') &&
                            (strlen(line) < sizeof(some_file)))
index 77f213d..113dc04 100644 (file)
@@ -1687,6 +1687,8 @@ int main(int argc, char *argv[])
                         break;
                case 'D':
                        /* Undocumented option debug log file */
+                       if (debug_log != NULL)
+                               fclose(debug_log);
                        debug_log = fopen(optarg, "a");
                        if (debug_log == NULL) {
                                printf("Cannot open %s for debug log\n",
index f0091de..5d84c95 100644 (file)
@@ -475,22 +475,22 @@ static int shmem_setup(void)
         rc = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED);
         if (rc != 0) {
                 fprintf(stderr, "Can't set shared mutex attr\n");
-                return rc;
+               goto out;
         }
 
         rc = pthread_condattr_setpshared(&cattr, PTHREAD_PROCESS_SHARED);
         if (rc != 0) {
                 fprintf(stderr, "Can't set shared cond attr\n");
-                return rc;
+               goto out;
         }
 
         pthread_mutex_init(&shared_data->mutex, &mattr);
         pthread_cond_init(&shared_data->cond, &cattr);
-
+out:
         pthread_mutexattr_destroy(&mattr);
         pthread_condattr_destroy(&cattr);
 
-        return 0;
+       return rc;
 }
 
 static inline void shmem_lock(void)
index 481c104..9f0af2e 100644 (file)
@@ -210,8 +210,10 @@ main (int argc, char **argv)
                 return (1);
 
         b = obdio_new_barrier (oid, bid, npeers);
-        if (b == NULL)
-                return (1);
+       if (b == NULL) {
+               rc = 1;
+               goto out;
+       }
 
         rc = 0;
         if (setup) {
@@ -230,7 +232,7 @@ main (int argc, char **argv)
         }
 
         free(b);
-
+out:
         obdio_disconnect(conn, 0);
 
         return (rc == 0 ? 0 : 1);