Received: from PACIFIC-CARRIER-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA29258; Wed, 20 Dec 95 02:59:04 EST
Received: from mercury.Sun.COM by MIT.EDU with SMTP
	id AA25141; Wed, 20 Dec 95 02:55:52 EST
Received: from Eng.Sun.COM by mercury.Sun.COM (Sun.COM)
	id XAA24286; Tue, 19 Dec 1995 23:55:58 -0800
Received: from caribe.eng.sun.com by Eng.Sun.COM (5.x/SMI-5.3)
	id AA05491; Tue, 19 Dec 1995 23:55:57 -0800
Received: from slapshot.eng.sun.com by caribe.eng.sun.com (5.x/SMI-SVR4)
	id AA18927; Tue, 19 Dec 1995 23:55:35 -0800
Received: (from schemers@localhost) by slapshot.eng.sun.com (8.6.12/8.6.12) id XAA02162; Tue, 19 Dec 1995 23:55:46 -0800
Date: Tue, 19 Dec 1995 23:55:46 -0800
From: Roland Schemers <schemers@Eng.Sun.COM>
Message-Id: <199512200755.XAA02162@slapshot.eng.sun.com>
To: krb5-bugs@MIT.EDU
Subject: memory leak...
Cc: warlord@Eng.Sun.COM
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Md5: PhSDvPnMt96bddpBZrlg6A==


Hi. I found a memory leak in:

(120195 snapshot) src/lib/krb5/os/hst_realm.c:krb5_get_host_realm

Basically what happens is profile_get_string mallocs the value for &realm:

       retval = profile_get_string(context->profile, "domain_realm", cp,
                                    0, (char *)NULL, &realm);

But later on you have:

    if (realm != (char *)NULL)
    {
        /* We found an exact match */
        if (!(cp = (char *)malloc(strlen(realm)+1)))
            return ENOMEM;
        strcpy(cp, realm);
        realm = cp;   <----------- this nukes the malloc value of realm
    }

Which blows away the malloc'd value for realm. I'm not sure how you want
to fix it, I think you can just say:

if (realm != (char*) NULL) 
{
     cp = realm;
}

But I haven't studied it close enough...

roland
