Whamcloud - gitweb
LU-17000 llite: fix memory leaks in error handling 61/58361/2
authorAndreas Dilger <adilger@whamcloud.com>
Tue, 11 Mar 2025 01:39:58 +0000 (19:39 -0600)
committerOleg Drokin <green@whamcloud.com>
Wed, 19 Mar 2025 23:36:22 +0000 (23:36 +0000)
Ensure that allocations are freed before returning in case of errors.

CoverityID: 457069 ("Resource leak")
CoverityID: 457073 ("Resource leak")
CoverityID: 457077 ("Resource leak")

Test-Parameters: trivial
Fixes: ae828cd3b0 ("LU-4684 llite: add lock for dir layout data")
Fixes: ed4a625d88 ("LU-13717 sec: filename encryption - digest support")
Fixes: 2e2b16c28b ("LU-11025 dne: support directory restripe")
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I5ff33a7243e1f536e5308f61451f205f232540e5
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/58361
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Arshad Hussain <arshad.hussain@aeoncomputing.com>
Reviewed-by: Timothy Day <timday@amazon.com>
Reviewed-by: Sebastien Buisson <sbuisson@ddn.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/llite/crypto.c
lustre/llite/llite_lib.c
lustre/llite/statahead.c
lustre/mdd/mdd_dir.c

index bcab6c3..da2b66d 100644 (file)
@@ -568,7 +568,7 @@ int ll_fname_disk_to_usr(struct inode *inode,
                         * enable further lookup requests.
                         */
                        if (!fid)
-                               return -EINVAL;
+                               GOTO(out_buf, rc = -EINVAL);
                        digest.ldf_fid = *fid;
                        memcpy(digest.ldf_excerpt,
                               LLCRYPT_EXTRACT_DIGEST(lltr.name, lltr.len),
@@ -588,10 +588,11 @@ int ll_fname_disk_to_usr(struct inode *inode,
 
        rc = llcrypt_fname_disk_to_usr(inode, hash, minor_hash, &lltr, oname);
 
-       kfree(buf);
        oname->name = oname->name - digested;
        oname->len = oname->len + digested;
 
+out_buf:
+       kfree(buf);
        return rc;
 }
 
index a7d36e1..c24cf29 100644 (file)
@@ -3831,13 +3831,13 @@ struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
                        return ERR_PTR(-EINVAL);
        }
 
-       if (op_data == NULL)
+       if (op_data == NULL) {
                OBD_ALLOC_PTR(op_data);
-       else
+               if (op_data == NULL)
+                       return ERR_PTR(-ENOMEM);
+       } else {
                op_data_alloc_inside = false;
-
-       if (op_data == NULL)
-               return ERR_PTR(-ENOMEM);
+       }
 
        ll_i2gids(op_data->op_suppgids, i1, i2);
        /* If the client is using a subdir mount and looks at what it sees as
index 828ff8b..e9560cb 100644 (file)
@@ -1212,12 +1212,13 @@ static int ll_statahead_by_list(struct ll_statahead_info *sai,
               smp_load_acquire(&sai->sai_task) &&
               lli->lli_sa_enabled) {
                struct lu_dirpage *dp;
-               struct lu_dirent  *ent;
+               struct lu_dirent *ent;
+               struct md_op_data *ret;
 
-               op_data = ll_prep_md_op_data(op_data, dir, dir, NULL, 0, 0,
-                                            LUSTRE_OPC_ANY, dir);
-               if (IS_ERR(op_data)) {
-                       rc = PTR_ERR(op_data);
+               ret = ll_prep_md_op_data(op_data, dir, dir, NULL, 0, 0,
+                                        LUSTRE_OPC_ANY, dir);
+               if (IS_ERR(ret)) {
+                       rc = PTR_ERR(ret);
                        break;
                }
 
index 12d7970..aa29642 100644 (file)
@@ -5023,7 +5023,7 @@ int mdd_dir_layout_shrink(const struct lu_env *env,
 
        lmv = lmv_buf.lb_buf;
        if (!lmv_is_sane(lmv))
-               RETURN(-EBADF);
+               GOTO(out_lmv, rc = -EBADF);
 
        lmu = mlc->mlc_buf.lb_buf;
 
@@ -5137,6 +5137,7 @@ out:
                mdd_object_put(env, stripe);
                mdd_object_put(env, pobj);
        }
+out_lmv:
        lu_buf_free(&lmv_buf);
        return rc;
 }