[Stgt-devel] [Patch 1/2] Fix potential memory leak with ibmvio

Mark Harvey markh794
Sun Jun 17 23:21:31 CEST 2007


>From 61ceaf62a3e896f86c65f6ea81c80b619f29d001 Mon Sep 17 00:00:00 2001
From: Mark Harvey <markh794 at gmail.com>
Date: Mon, 18 Jun 2007 06:50:39 +1000
Subject: Fix memory leak in ibmvio -> spc_inquiry() path

Allocating data = valloc() twice when calling spc_inquiry()

Signed-off-by: Mark Harvey <markh794 at gmail.com>
---
 usr/ibmvio/ibmvio.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/usr/ibmvio/ibmvio.c b/usr/ibmvio/ibmvio.c
index ff91f14..ab2c0f2 100644
--- a/usr/ibmvio/ibmvio.c
+++ b/usr/ibmvio/ibmvio.c
@@ -142,17 +142,16 @@ static int ibmvio_inquiry(int host_no, struct scsi_cmd *cmd)
 	if (((scb[1] & 0x3) == 0x3) || (!(scb[1] & 0x3) && scb[2]))
 		goto sense;
 
-	data = valloc(pagesize);
-	if (!data) {
-		key = HARDWARE_ERROR;
-		asc = 0;
-		goto sense;
-	}
-	memset(data, 0, pagesize);
-
 	dprintf("%x %x\n", scb[1], scb[2]);
 
 	if (!(scb[1] & 0x3)) {
+		data = valloc(pagesize);
+		if (!data) {
+			key = HARDWARE_ERROR;
+			asc = 0;
+			goto sense;
+		}
+		memset(data, 0, pagesize);
 		cmd->len = __ibmvio_inquiry(host_no, cmd, data);
 		ret = SAM_STAT_GOOD;
 	} else
-- 
1.5.2.1








More information about the stgt mailing list