Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 1 Mar 2000 00:10:02 -0800 (PST)
From:      "Vladimir B. Grebenschikov" <vova@express.ru>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: bin/17084: memory leak in getcap.c (libc)
Message-ID:  <200003010810.AAA41191@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

The following reply was made to PR bin/17084; it has been noted by GNATS.

From: "Vladimir B. Grebenschikov" <vova@express.ru>
To: Ruslan Ermilov <ru@ucb.crimea.ua>
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 <stdio.h>
 > > #include <sys/types.h>
 > > #include <login_cap.h>
 > > #include <pwd.h>
 > > 
 > > 
 > > 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003010810.AAA41191>