Skip to contentSkip to conversation

erofs-utils: decompress: fix QPL job leak on error paths

PATCH In review Vi-shub 2 participants 3 messages Mar 20 Library code

lore
Share & tools
lore

Vi-shub

author
#0 lore raw

PATCH v3 1/1 erofs-utils: decompress: fix QPL job leak on error paths

Two early returns in z_erofs_decompress_qpl() after a successful z_erofs_qpl_get_job() skip the cleanup, leaking the job handle. Use goto out_inflate_end instead.

---
 lib/decompress.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
lib/decompress.c +8 -4
index e7ec83e..eb696d3 100644
@@ -196,13 +196,17 @@ static int z_erofs_decompress_qpl(struct z_erofs_decompress_req *rq)
 		return PTR_ERR(job);
 
 	inputmargin = z_erofs_fixup_insize(src, rq->inputsize);
-	if (inputmargin >= rq->inputsize)
-		return -EFSCORRUPTED;
+	if (inputmargin >= rq->inputsize) {
+		ret = -EFSCORRUPTED;
+		goto out_inflate_end;
+	}
 
 	if (rq->decodedskip) {
 		buff = malloc(rq->decodedlength);
-		if (!buff)
-			return -ENOMEM;
+		if (!buff) {
+			ret = -ENOMEM;
+			goto out_inflate_end;
+		}
 		dest = buff;
 	}
 
Signature · 1 line
2.39.1.windows.1
#1 lore raw
Quoted 5 lines · Vi-shub

Two early returns in z_erofs_decompress_qpl() after a successful z_erofs_qpl_get_job() skip the cleanup, leaking the job handle. Use goto out_inflate_end instead.

LGTM, will apply.

Thanks,
Gao Xiang

#2 lore raw

Hi Gao,

Got it. Thanks for applying.

Shubham Vishwakarma

Quoted 14 lines · Gao Xiang
Quoted 5 lines · Vi-shub

Two early returns in z_erofs_decompress_qpl() after a successful z_erofs_qpl_get_job() skip the cleanup, leaking the job handle. Use goto out_inflate_end instead.

LGTM, will apply.

Thanks,
Gao Xiang