From 9c14d8067c773eda095e727e501280e9da4c2f9a Mon Sep 17 00:00:00 2001 From: Sebastien Buisson Date: Fri, 18 Jan 2013 16:00:40 +0100 Subject: [PATCH] LU-2644 build: fix 'resource leak' errors Fix 'resource leak' defects found by Coverity version 6.0.3: Resource leak (RESOURCE_LEAK) Variable going out of scope leaks the storage it points to. Signed-off-by: Sebastien Buisson Change-Id: I9fae1905848a83393b7258449bfafd1fc0a342a7 Reviewed-on: http://review.whamcloud.com/5131 Reviewed-by: Bob Glossman Reviewed-by: Keith Mannthey Tested-by: Hudson Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/llite/namei.c | 2 +- lustre/lov/lov_obd.c | 2 +- lustre/mgc/mgc_request.c | 4 +++- lustre/obdclass/obd_mount.c | 3 ++- lustre/osd-ldiskfs/osd_quota_fmt.c | 3 ++- lustre/utils/liblustreapi.c | 3 +-- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lustre/llite/namei.c b/lustre/llite/namei.c index 3622909..6f897e3 100644 --- a/lustre/llite/namei.c +++ b/lustre/llite/namei.c @@ -1202,12 +1202,12 @@ int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir) rc = obd_destroy(NULL, ll_i2dtexp(dir), oa, lsm, &oti, ll_i2mdexp(dir), oc); capa_put(oc); - OBDO_FREE(oa); if (rc) CERROR("obd destroy objid "LPX64" error %d\n", lsm->lsm_object_id, rc); out_free_memmd: obd_free_memmd(ll_i2dtexp(dir), &lsm); + OBDO_FREE(oa); out: return rc; } diff --git a/lustre/lov/lov_obd.c b/lustre/lov/lov_obd.c index 838e713..3c5738a 100644 --- a/lustre/lov/lov_obd.c +++ b/lustre/lov/lov_obd.c @@ -2269,7 +2269,7 @@ static int lov_fiemap(struct lov_obd *lov, __u32 keylen, void *key, fm_end_offset = fiemap_calc_fm_end_offset(fiemap, lsm, fm_start, fm_end, &start_stripe); if (fm_end_offset == -EINVAL) - return -EINVAL; + GOTO(out, rc = -EINVAL); if (fiemap->fm_extent_count == 0) { get_num_extents = 1; diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index 0c2f107..4550de5 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -1264,8 +1264,10 @@ static int mgc_apply_recover_logs(struct obd_device *mgc, } else { LASSERT(IS_MDT(lsi)); rc = server_name2svname(lsi->lsi_svname, inst, NULL); - if (rc) + if (rc) { + OBD_FREE(inst, CFS_PAGE_SIZE); RETURN(-EINVAL); + } pos = strlen(inst); } diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 3eaf93f..411efa2 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -969,6 +969,7 @@ int lustre_register_osp_item(char *ospname, struct obd_export **exp, OBD_ALLOC_PTR(uuid); if (uuid == NULL) { mutex_unlock(&osp_register_list_lock); + OBD_FREE_PTR(ori); RETURN(-ENOMEM); } memcpy(uuid->uuid, ospname, strlen(ospname)); @@ -1178,7 +1179,7 @@ static int lustre_osp_add_conn(struct lustre_cfg *cfg, OBD_ALLOC_PTR(bufs); if (bufs == NULL) - RETURN(-ENOMEM); + GOTO(out, rc = -ENOMEM); lustre_cfg_bufs_reset(bufs, ospname); lustre_cfg_bufs_set_string(bufs, 1, diff --git a/lustre/osd-ldiskfs/osd_quota_fmt.c b/lustre/osd-ldiskfs/osd_quota_fmt.c index 575d78b..542f7618 100644 --- a/lustre/osd-ldiskfs/osd_quota_fmt.c +++ b/lustre/osd-ldiskfs/osd_quota_fmt.c @@ -218,7 +218,7 @@ int walk_block_dqentry(const struct lu_env *env, struct osd_object *obj, int type, uint blk, uint index, struct osd_it_quota *it) { - dqbuf_t buf = getdqbuf(); + dqbuf_t buf; loff_t ret = 0; struct lustre_disk_dqdbheader *dqhead; int i, dqblk_sz; @@ -232,6 +232,7 @@ int walk_block_dqentry(const struct lu_env *env, struct osd_object *obj, RETURN(1); } + buf = getdqbuf(); dqhead = (struct lustre_disk_dqdbheader *)buf; dqblk_sz = sizeof(struct lustre_disk_dqblk_v2); if (!buf) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index bb1c0b6..eefd0ea 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -3111,6 +3111,7 @@ static int rmtacl_notify(int ops) } rc = ioctl(fd, LL_IOC_RMTACL, ops); + close(fd); if (rc < 0) { rc = -errno; llapi_error(LLAPI_MSG_ERROR, rc, "ioctl %d\n", fd); @@ -3122,8 +3123,6 @@ static int rmtacl_notify(int ops) out: endmntent(fp); - if (fd >= 0) - close(fd); return ((rc != 0) ? rc : found); } -- 1.8.3.1