Skip to contentSkip to conversation

fs/iomap: fix memory leak on error condition

PATCH In review Garry McNulty 2 participants 3 messages Feb 21, 2018 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/iomap: fix memory leak on error condition

If the call to is_sync_kiocb() fails an error is returned without freeing dio. Set the return code and jump to out_free_dio.

Detected by CoverityScan, CID 1429424 ("Resource leak")

---
 fs/iomap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/iomap.c +4 -2
index afd163586aa0..65c5db38c15a 100644
@@ -1063,8 +1063,10 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 		iomap_dio_set_error(dio, ret);
 
 	if (!atomic_dec_and_test(&dio->ref)) {
-		if (!is_sync_kiocb(iocb))
-			return -EIOCBQUEUED;
+		if (!is_sync_kiocb(iocb)) {
+			ret = -EIOCBQUEUED;
+			goto out_free_dio;
+		}
 
 		for (;;) {
 			set_current_state(TASK_UNINTERRUPTIBLE);
Signature · 1 line
2.14.3
#1 lore raw
Quoted 4 lines · Garry McNulty

If the call to is_sync_kiocb() fails an error is returned without freeing dio. Set the return code and jump to out_free_dio.

Detected by CoverityScan, CID 1429424 ("Resource leak")

Coverity is wrong.

Quoted 10 lines
---
 fs/iomap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/iomap.c +0 -0
index afd163586aa0..65c5db38c15a 100644

fs/iomap.c iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 1069

Quoted 9 lines
fs/iomap.c +4 -2
@@ -1063,8 +1063,10 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
 		iomap_dio_set_error(dio, ret);
 
 	if (!atomic_dec_and_test(&dio->ref)) {
-		if (!is_sync_kiocb(iocb))
-			return -EIOCBQUEUED;
+		if (!is_sync_kiocb(iocb)) {
+			ret = -EIOCBQUEUED;
+			goto out_free_dio;
+		}

This is where we return after AIO submission. The struct dio has already been attached to the bio we have submitted, and will be freed on IO completion. We are simply not waiting for IO completion here, instead leaving it to the completion code to free the struct dio and pass the completion status to the AIO code appropriately.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
#2 lore raw
Quoted 21 lines · Dave Chinner
Quoted 4 lines · Garry McNulty

If the call to is_sync_kiocb() fails an error is returned without freeing dio. Set the return code and jump to out_free_dio.

Detected by CoverityScan, CID 1429424 ("Resource leak")

Coverity is wrong.

Quoted 12 lines
---
 fs/iomap.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/iomap.c +0 -0
index afd163586aa0..65c5db38c15a 100644
@@ -1063,8 +1063,10 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
              iomap_dio_set_error(dio, ret);
 
Quoted 14 lines

fs/iomap.c iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, · line 1069

Quoted 7 lines
fs/iomap.c +4 -2
      if (!atomic_dec_and_test(&dio->ref)) {
-             if (!is_sync_kiocb(iocb))
-                     return -EIOCBQUEUED;
+             if (!is_sync_kiocb(iocb)) {
+                     ret = -EIOCBQUEUED;
+                     goto out_free_dio;
+             }

This is where we return after AIO submission. The struct dio has already been attached to the bio we have submitted, and will be freed on IO completion. We are simply not waiting for IO completion here, instead leaving it to the completion code to free the struct dio and pass the completion status to the AIO code appropriately.

ah OK, thanks for reviewing and for the explanation.

Cheers

Garry