[Stgt-devel] [Patch 1/6] Fix potential memory leak

Mark Harvey markh794
Wed Jun 20 09:57:44 CEST 2007


>From f25303a09128973d77df0bb49926001212548f1d Mon Sep 17 00:00:00 2001
From: Mark Harvey <markh794 at gmail.com>
Date: Wed, 20 Jun 2007 17:31:32 +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 5a2f8fe..1b1785d 100644
--- a/usr/ibmvio/ibmvio.c
+++ b/usr/ibmvio/ibmvio.c
@@ -145,17 +145,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