public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fix for memory leak in scsi_prep_fn
@ 2003-01-28 18:32 James Bottomley
  2003-01-28 18:52 ` James Bottomley
  0 siblings, 1 reply; 2+ messages in thread
From: James Bottomley @ 2003-01-28 18:32 UTC (permalink / raw)
  To: SCSI Mailing List; +Cc: Russell King

[-- Attachment #1: Type: text/plain, Size: 192 bytes --]



This should fix the memory leak Russell King spotted if command
initialisation fails in the request prep function.

The patch is against the scsi-combined-2.5 bkbits.net repository.

James


[-- Attachment #2: Type: text/plain, Size: 1176 bytes --]

===== drivers/scsi/scsi_lib.c 1.63 vs edited =====
--- 1.63/drivers/scsi/scsi_lib.c	Tue Jan 28 10:19:35 2003
+++ edited/drivers/scsi/scsi_lib.c	Tue Jan 28 12:29:45 2003
@@ -796,6 +796,8 @@
 	struct Scsi_Device_Template *STpnt;
 	Scsi_Cmnd *SCpnt;
 	Scsi_Device *SDpnt;
+	int ret;
+
 
 	SDpnt = (Scsi_Device *) q->queuedata;
 	BUG_ON(!SDpnt);
@@ -862,8 +864,6 @@
 	 */
 
 	if (req->flags & (REQ_CMD | REQ_BLOCK_PC)) {
-		int ret;
-
 		/*
 		 * This will do a couple of things:
 		 *  1) Fill in the actual SCSI command.
@@ -884,19 +884,27 @@
 		 * required).
 		 */
 		if ((ret = scsi_init_io(SCpnt)))
-			return ret;
+			goto fail_release_cmd;
 		
 		/*
 		 * Initialize the actual SCSI command for this request.
 		 */
 		if (!STpnt->init_command(SCpnt)) {
-			scsi_release_buffers(SCpnt);
-			return BLKPREP_KILL;
+			ret = BLKPREP_KILL;
+			goto fail_release_buffers;
 		}
 	}
 	/* The request is now prepped, no need to come back here */
 	req->flags |= REQ_DONTPREP;
 	return BLKPREP_OK;
+
+ fail_release_buffers:
+	scsi_release_buffers(SCpnt);
+
+ fail_release_cmd:
+	scsi_put_command(SCpnt);
+
+	return ret;
 }
 
 /*

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2003-01-28 18:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-01-28 18:32 [PATCH] fix for memory leak in scsi_prep_fn James Bottomley
2003-01-28 18:52 ` James Bottomley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox