From: Dmitry Eremin Date: Fri, 21 Feb 2014 12:33:30 +0000 (+0400) Subject: LU-4629 utils: fix rsources leak X-Git-Tag: 2.5.57~55 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=e0d2bfe3b93d5179c9aee4a65e1695fa4c7779ed;ds=sidebyside LU-4629 utils: fix rsources leak 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 Change-Id: I47a1c44d8b1cfd8500ca71958814b8a23d6fff2b Reviewed-on: http://review.whamcloud.com/9343 Tested-by: Jenkins Reviewed-by: John L. Hammond Tested-by: Maloo Reviewed-by: James Nunez Reviewed-by: James Simmons Reviewed-by: Andreas Dilger Reviewed-by: Oleg Drokin --- diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 5af9305..ef03636 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -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))) diff --git a/lustre/utils/lustre_rsync.c b/lustre/utils/lustre_rsync.c index 77f213d..113dc04 100644 --- a/lustre/utils/lustre_rsync.c +++ b/lustre/utils/lustre_rsync.c @@ -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", diff --git a/lustre/utils/obd.c b/lustre/utils/obd.c index f0091de..5d84c95 100644 --- a/lustre/utils/obd.c +++ b/lustre/utils/obd.c @@ -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) diff --git a/lustre/utils/obdbarrier.c b/lustre/utils/obdbarrier.c index 481c104..9f0af2e 100644 --- a/lustre/utils/obdbarrier.c +++ b/lustre/utils/obdbarrier.c @@ -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);