Skip to contentSkip to conversation

block: Fix memory leak in rw_copy_check_uvector() handling

PATCH Applied Christian Engelmayer 2 participants 2 messages Jan 19, 2014 – Jan 22, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 block: Fix memory leak in rw_copy_check_uvector() handling

Fix a memory leak in the error handling path of function sg_io() that is used during the processing of scsi ioctl. Memory already allocated by rw_copy_check_uvector() needs to be freed correctly. Detected by Coverity: CID 1128953.

---
 block/scsi_ioctl.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/scsi_ioctl.c +4 -2
index 625e3e4..2648797 100644
@@ -323,12 +323,14 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
 
 	if (hdr->iovec_count) {
 		size_t iov_data_len;
-		struct iovec *iov;
+		struct iovec *iov = NULL;
 
 		ret = rw_copy_check_uvector(-1, hdr->dxferp, hdr->iovec_count,
 					    0, NULL, &iov);
-		if (ret < 0)
+		if (ret < 0) {
+			kfree(iov);
 			goto out;
+		}
 
 		iov_data_len = ret;
 		ret = 0;
Signature · 1 line
1.8.3.2
maintainer Applied
#1 lore raw
Quoted 4 lines · Christian Engelmayer

Fix a memory leak in the error handling path of function sg_io() that is used during the processing of scsi ioctl. Memory already allocated by rw_copy_check_uvector() needs to be freed correctly. Detected by Coverity: CID 1128953.

Applied, thanks.

Signature · 1 line
Jens Axboe