From owner-freebsd-bugs Wed Mar 1 0:10: 6 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 3B57337BE24 for ; Wed, 1 Mar 2000 00:10:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id AAA41191; Wed, 1 Mar 2000 00:10:02 -0800 (PST) (envelope-from gnats@FreeBSD.org) Date: Wed, 1 Mar 2000 00:10:02 -0800 (PST) Message-Id: <200003010810.AAA41191@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: "Vladimir B. Grebenschikov" Subject: Re: bin/17084: memory leak in getcap.c (libc) Reply-To: "Vladimir B. Grebenschikov" 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: "Vladimir B. Grebenschikov" To: Ruslan Ermilov Cc: freebsd-gnats-submit@FreeBSD.ORG Subject: Re: bin/17084: memory leak in getcap.c (libc) Date: Sat, 1 May 1999 01:18:50 +0400 (MSD) On Wed, 1 Mar 2000, Ruslan Ermilov wrote: > 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(). I am a bit missunderstand you, my alghorithm is: cycle begin: call login_getclassbyname call login_close go to cycle begin exectly what you say: login_close called before each subsequient call of login_getclassbyname. > : 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 > -- TSB Russian Express, Moscow Vladimir B. Grebenschikov, vova@express.ru To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message