Date: Wed, 1 Mar 2000 00:00:04 -0800 (PST) From: Ruslan Ermilov <ru@ucb.crimea.ua> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/17084: memory leak in getcap.c (libc) Message-ID: <200003010800.AAA40271@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: Ruslan Ermilov <ru@ucb.crimea.ua>
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 <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().
: 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003010800.AAA40271>
