From antoine@massena-4-82-67-196-50.fbx.proxad.net  Fri Feb 25 14:27:32 2005
Return-Path: <antoine@massena-4-82-67-196-50.fbx.proxad.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 8FEB916A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 25 Feb 2005 14:27:32 +0000 (GMT)
Received: from barton.dreadbsd.org (massena-4-82-67-196-50.fbx.proxad.net [82.67.196.50])
	by mx1.FreeBSD.org (Postfix) with ESMTP id B734A43D76
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 25 Feb 2005 14:27:31 +0000 (GMT)
	(envelope-from antoine@massena-4-82-67-196-50.fbx.proxad.net)
Received: from barton.dreadbsd.org (localhost [127.0.0.1])
	by barton.dreadbsd.org (8.13.3/8.13.1) with ESMTP id j1PERSss019222
	for <FreeBSD-gnats-submit@freebsd.org>; Fri, 25 Feb 2005 15:27:31 +0100 (CET)
	(envelope-from antoine@massena-4-82-67-196-50.fbx.proxad.net)
Received: (from antoine@localhost)
	by barton.dreadbsd.org (8.13.3/8.13.1/Submit) id j1PERRxm019221;
	Fri, 25 Feb 2005 15:27:27 +0100 (CET)
	(envelope-from antoine)
Message-Id: <200502251427.j1PERRxm019221@barton.dreadbsd.org>
Date: Fri, 25 Feb 2005 15:27:27 +0100 (CET)
From: Antoine Brodin <antoine.brodin@laposte.net>
Reply-To: Antoine Brodin <antoine.brodin@laposte.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [Patch] Potential memory leak in lge(4)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         78072
>Category:       kern
>Synopsis:       [lge] [patch] Potential memory leak in lge(4)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    yongari
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 25 14:30:17 GMT 2005
>Closed-Date:    Tue Mar 18 02:02:36 UTC 2008
>Last-Modified:  Tue Mar 18 02:10:00 UTC 2008
>Originator:     Antoine Brodin
>Release:        FreeBSD 6.0-CURRENT i386
>Organization:
none
>Environment:
System: FreeBSD barton.dreadbsd.org 6.0-CURRENT FreeBSD 6.0-CURRENT #0: Thu Feb 24 14:18:22 CET 2005 antoine@barton.dreadbsd.org:/usr/obj/usr/src/sys/BARTON i386
>Description:
If malloc(9) fails line 791 of if_lge.c, the jumbo buffer block and the
free jumbo list entries already allocated will be leaked.
>How-To-Repeat:
I haven't got any lge(4) NIC.
>Fix:

Patch attached:

--- if_lge.diff begins here ---
Index: dev/lge/if_lge.c
===================================================================
RCS file: /home/ncvs/src/sys/dev/lge/if_lge.c,v
retrieving revision 1.36
diff -u -p -r1.36 if_lge.c
--- dev/lge/if_lge.c	6 Jan 2005 01:42:53 -0000	1.36
+++ dev/lge/if_lge.c	25 Feb 2005 12:24:46 -0000
@@ -791,6 +791,7 @@ lge_alloc_jumbo_mem(sc)
 		entry = malloc(sizeof(struct lge_jpool_entry), 
 		    M_DEVBUF, M_NOWAIT);
 		if (entry == NULL) {
+			lge_free_jumbo_mem(sc);
 			printf("lge%d: no memory for jumbo "
 			    "buffer queue!\n", sc->lge_unit);
 			return(ENOBUFS);
@@ -807,10 +808,9 @@ static void
 lge_free_jumbo_mem(sc)
 	struct lge_softc	*sc;
 {
-	int			i;
 	struct lge_jpool_entry	*entry;
 
-	for (i = 0; i < LGE_JSLOTS; i++) {
+	while (!SLIST_EMPTY(&sc->lge_jfree_listhead)) {
 		entry = SLIST_FIRST(&sc->lge_jfree_listhead);
 		SLIST_REMOVE_HEAD(&sc->lge_jfree_listhead, jpool_entries);
 		free(entry, M_DEVBUF);
--- if_lge.diff ends here ---


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-net 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Mar 5 03:39:40 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=78072 
Responsible-Changed-From-To: freebsd-net->yongari 
Responsible-Changed-By: yongari 
Responsible-Changed-When: Wed Mar 5 04:03:50 UTC 2008 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=78072 
State-Changed-From-To: open->patched 
State-Changed-By: yongari 
State-Changed-When: Wed Mar 5 05:36:28 UTC 2008 
State-Changed-Why:  
Committed with minor modification. 
Thanks for reporting and the patch. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=78072 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/78072: commit references a PR
Date: Wed,  5 Mar 2008 05:36:18 +0000 (UTC)

 yongari     2008-03-05 05:36:09 UTC
 
   FreeBSD src repository
 
   Modified files:
     sys/dev/lge          if_lge.c 
   Log:
   Plug memory leak in jumbo buffer allocation failure path.
   Patch in the PR was modified to check active jumbo buffers in use
   and other possible jumbo buffer leak.
   
   Jumbo buffer usage in lge(4) still wouldn't be reliable due to lack
   of driver lock in local jumbo buffer allocator. Either introduce
   a new lock to protect jumbo buffer or switch to UMA backed page
   allocator for jumbo frame is required.
   
   PR:     kern/78072
   
   Revision  Changes    Path
   1.53      +12 -4     src/sys/dev/lge/if_lge.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/78072: commit references a PR
Date: Tue, 18 Mar 2008 01:53:51 +0000 (UTC)

 yongari     2008-03-18 01:53:46 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     sys/dev/lge          if_lge.c 
   Log:
   MFC if_lge.c rev 1.53 to RELENG_7:
     Plug memory leak in jumbo buffer allocation failure path.
     Patch in the PR was modified to check active jumbo buffers in use
     and other possible jumbo buffer leak.
   
     Jumbo buffer usage in lge(4) still wouldn't be reliable due to lack
     of driver lock in local jumbo buffer allocator. Either introduce
     a new lock to protect jumbo buffer or switch to UMA backed page
     allocator for jumbo frame is required.
   
     PR:     kern/78072
   
   Revision  Changes    Path
   1.50.2.2  +12 -4     src/sys/dev/lge/if_lge.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: yongari 
State-Changed-When: Tue Mar 18 02:02:12 UTC 2008 
State-Changed-Why:  
MFC done. Thanks for reporting! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=78072 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/78072: commit references a PR
Date: Tue, 18 Mar 2008 02:01:29 +0000 (UTC)

 yongari     2008-03-18 02:01:22 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_6)
     sys/dev/lge          if_lge.c 
   Log:
   MFC if_lge.c rev 1.53 to RELENG_6:
     Plug memory leak in jumbo buffer allocation failure path.
     Patch in the PR was modified to check active jumbo buffers in use
     and other possible jumbo buffer leak.
   
     Jumbo buffer usage in lge(4) still wouldn't be reliable due to lack
     of driver lock in local jumbo buffer allocator. Either introduce
     a new lock to protect jumbo buffer or switch to UMA backed page
     allocator for jumbo frame is required.
   
     I've removed informational device_printf in lge_free_jumbo_mem as
     lge_dev member variable in softc does not exist on RELENG_6.
     if_printf can't be used as sc->lge_ifp could be NULL.
   
     PR:   kern/78072
   
   Revision  Changes    Path
   1.39.2.6  +10 -4     src/sys/dev/lge/if_lge.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
