From nobody@FreeBSD.org  Mon Oct 17 19:57:51 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 16FC61065672
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 17 Oct 2011 19:57:51 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 029208FC0C
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 17 Oct 2011 19:57:51 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p9HJvo8L091468
	for <freebsd-gnats-submit@FreeBSD.org>; Mon, 17 Oct 2011 19:57:50 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p9HJvoRh091465;
	Mon, 17 Oct 2011 19:57:50 GMT
	(envelope-from nobody)
Message-Id: <201110171957.p9HJvoRh091465@red.freebsd.org>
Date: Mon, 17 Oct 2011 19:57:50 GMT
From: Arnaud Lacombe <lacombar@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Kernel fails to report negative malloc type statistics
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         161755
>Category:       kern
>Synopsis:       Kernel fails to report negative malloc type statistics
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Oct 17 20:00:26 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Arnaud Lacombe
>Release:        10-current
>Organization:
n/a
>Environment:
>Description:
When malloc-type are uninit, a verification is made to ensure that no memory has been leaked, however, it fails to report if memory allocation have been badly accounted (ie `malloc(X, M_FOO)' followed by `free(Y, M_BAR)').


from `sys/kern/kern_malloc.c':
 
if (temp_allocs > 0 || temp_bytes > 0) {
    printf("Warning: memory type %s leaked memory on destroy "
        "(%ld allocations, %ld bytes leaked).\n", mtp->ks_shortdesc,

this do not report whenever `temp_allocs' or `temp_bytes' are negative, which should be reported, else, whatever is printed can not be trusted.
>How-To-Repeat:

>Fix:
Patch available at:

https://github.com/lacombar/freebsd/commit/8b498200a0389ec48021959e32eaf198c075b6ca

>Release-Note:
>Audit-Trail:
>Unformatted:
