From owner-freebsd-bugs Thu Aug 15 4:10:11 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3E79137B400 for ; Thu, 15 Aug 2002 04:10:04 -0700 (PDT) Received: from freefall.freebsd.org (freefall.FreeBSD.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 89ADB43E86 for ; Thu, 15 Aug 2002 04:10:03 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.4/8.12.4) with ESMTP id g7FBA3JU002194 for ; Thu, 15 Aug 2002 04:10:03 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.4/8.12.4/Submit) id g7FBA34Z002193; Thu, 15 Aug 2002 04:10:03 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 0555D37B400 for ; Thu, 15 Aug 2002 04:09:24 -0700 (PDT) Received: from www.freebsd.org (www.FreeBSD.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id BC21043E70 for ; Thu, 15 Aug 2002 04:09:23 -0700 (PDT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.4/8.12.4) with ESMTP id g7FB9NOT063963 for ; Thu, 15 Aug 2002 04:09:23 -0700 (PDT) (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.4/8.12.4/Submit) id g7FB9NMM063962; Thu, 15 Aug 2002 04:09:23 -0700 (PDT) Message-Id: <200208151109.g7FB9NMM063962@www.freebsd.org> Date: Thu, 15 Aug 2002 04:09:23 -0700 (PDT) From: Hovik Melikyan To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: misc/41684: realloc() to 0 loses 16 bytes of memory regardless of the previous block size Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >Number: 41684 >Category: misc >Synopsis: realloc() to 0 loses 16 bytes of memory regardless of the previous block size >Confidential: no >Severity: serious >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Aug 15 04:10:02 PDT 2002 >Closed-Date: >Last-Modified: >Originator: Hovik Melikyan >Release: 4.6-RELEASE, also 4.5-PRERELEASE >Organization: NetFlute.com >Environment: FreeBSD london.imc.am 4.6-RELEASE FreeBSD 4.6-RELEASE #0: Tue Jun 11 06:14:12 GMT 2002 murray@builder.freebsdmall.com:/usr/src/sys/compile/GENERIC i386 >Description: realloc() with the size parameter set to 0 loses 16 bytes of memory regardless of the previous block size, e.g. p = realloc(p, 0); >How-To-Repeat: run this program and watch its resources with top: #include #include int main() { int i, j; void *p; for (i = 0; i < 10; i++) { for (j = 0; j < 1000; j++) { p = malloc(12345); /* the block size doesn't matter */ p = realloc(p, 0); /* replace this with free(p) to avoid memory leak */ /* here we lose 16 bytes of memory */ } puts("Press any key:"); getchar(); } return 0; } >Fix: write your own wrapper for realloc() which would check the size parameter and call free() if it's 0. >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message