From owner-freebsd-bugs Wed Mar 1 0: 0: 9 2000 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 3843237BD4D for ; Wed, 1 Mar 2000 00:00:05 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id AAA40271; Wed, 1 Mar 2000 00:00:04 -0800 (PST) (envelope-from gnats@FreeBSD.org) Date: Wed, 1 Mar 2000 00:00:04 -0800 (PST) Message-Id: <200003010800.AAA40271@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Ruslan Ermilov Subject: Re: bin/17084: memory leak in getcap.c (libc) Reply-To: Ruslan Ermilov Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/17084; it has been noted by GNATS. From: Ruslan Ermilov To: vova@express.ru Cc: freebsd-gnats-submit@FreeBSD.ORG Subject: Re: bin/17084: memory leak in getcap.c (libc) Date: Wed, 1 Mar 2000 09:56:39 +0200 On Tue, Feb 29, 2000 at 03:20:14PM -0800, vova@express.ru wrote: > > Compile ang run program below > and all your memory will eaten very quckly > each itteration "eats" about 1.5k memory > --- > I have dip a bit into problem and found that memory leaks in > cgetent() called from login_getclassbyname() > >How-To-Repeat: > #include > #include > #include > #include > > > main() > { > > struct passwd *ent; > int uid; > > ent = getpwnam("nobody"); > while(1) { > login_cap_t *lc; > uid = ent->pw_uid; > if ( (lc = login_getclassbyname("root", ent)) == NULL ) > perror("login_getclassbyname: "); > login_close(lc); > } > } > Your code sucks :-) You should be calling login_close() before each subsequent call of function returning login_cap_t object, i.e. login_getclassbyname(), login_getclass(), login_getpwclass() and login_getuserclass(). : The login_cap interface provides a convenient means of retrieving login : class records with all tc= references expanded. A program will typically : call one of login_getclass(), login_getpwclass(), login_getuserclass() or : login_getclassbyname() according to its requirements. Each of these : functions returns a login capabilities structure, login_cap_t which may : subsequently be used to interrogate the database for specific values us- : ing the rest of the API. Once the login_cap_t is of no further use, the : login_close() function should be called to free all resources used. Cheers, -- Ruslan Ermilov Sysadmin and DBA of the ru@ucb.crimea.ua United Commercial Bank, ru@FreeBSD.org FreeBSD committer, +380.652.247.647 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message