From: dholland Date: Sun, 13 Jul 2008 20:07:48 +0000 (+0000) Subject: Clarify how one is supposed to use the pointers returned by getutentries() X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/commitdiff_plain/ee6e757230838de21b94218e463f2d43979e3aa9?ds=sidebyside Clarify how one is supposed to use the pointers returned by getutentries() (the utmpentry.c code), specifically with respect to who owns them and when to free them. Now they're owned by utmpentry.c, only. Abolish the freeutentries() function, which was the wrong abstraction; add instead endutentries(), which flushes out the internally managed memory. Update callers as necessary. Some (e.g. talkd) had been leaking memory; others (e.g. syslogd) had been accidentally freeing and reloading utmp more often than necessary. There are a couple untidy bits in users and rwhod that someone should look after sometime, maybe. Fixes PR bin/35131, which was about talkd's memory leak. --- diff --git a/dm/dm.c b/dm/dm.c index 2518c369..24833da5 100644 --- a/dm/dm.c +++ b/dm/dm.c @@ -1,4 +1,4 @@ -/* $NetBSD: dm.c,v 1.24 2007/12/15 19:44:40 perry Exp $ */ +/* $NetBSD: dm.c,v 1.25 2008/07/13 20:07:48 dholland Exp $ */ /* * Copyright (c) 1987, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1987, 1993\n\ #if 0 static char sccsid[] = "@(#)dm.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: dm.c,v 1.24 2007/12/15 19:44:40 perry Exp $"); +__RCSID("$NetBSD: dm.c,v 1.25 2008/07/13 20:07:48 dholland Exp $"); #endif #endif /* not lint */ @@ -247,15 +247,10 @@ load(void) int users(void) { - static struct utmpentry *ohead = NULL; struct utmpentry *ep; int nusers; nusers = getutentries(NULL, &ep); - if (ep != ohead) { - freeutentries(ep); - ohead = ep; - } return nusers; }