* g_cnffile.c (krb__get_srvtabname): Keep strdup()ed string in a
authorTom Yu <tlyu@mit.edu>
Mon, 3 Mar 2003 07:49:34 +0000 (07:49 +0000)
committerTom Yu <tlyu@mit.edu>
Mon, 3 Mar 2003 07:49:34 +0000 (07:49 +0000)
static variable and free it called again; this prevents a memory
leak.

ticket: 1357

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15215 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb4/ChangeLog
src/lib/krb4/g_cnffile.c

index 6ae5f55eb1188180c81e8ac04853d5a6fed5995d..bd31edc55b26af3fd9c2b3a35eaeaf22239c706e 100644 (file)
@@ -1,3 +1,9 @@
+2003-03-03  Tom Yu  <tlyu@mit.edu>
+
+       * g_cnffile.c (krb__get_srvtabname): Keep strdup()ed string in a
+       static variable and free it called again; this prevents a memory
+       leak.
+
 2003-02-28  Ezra Peisach  <epeisach@bu.edu>
 
        * Makefile.in (clean-unix): Remove krb_err_txt.c on clean. Update
index c31a9d2190548819c550f671267c17de6db2a3e0..8d61f50565aaef7576489682d057d10b288b7ad0 100644 (file)
@@ -56,7 +56,7 @@ krb__get_srvtabname(default_srvtabname)
        const char* names[3];
        char **full_name = 0, **cpp;
        krb5_error_code retval;
-       char *retname;
+       static char *retname;
 
        if (!krb5__krb4_context)
                krb5_init_context(&krb5__krb4_context);
@@ -67,6 +67,8 @@ krb__get_srvtabname(default_srvtabname)
            retval = profile_get_values(krb5__krb4_context->profile, names, 
                                        &full_name);
            if (retval == 0 && full_name && full_name[0]) {
+               if (retname != NULL)
+                   free(retname);
                retname = strdup(full_name[0]);
                for (cpp = full_name; *cpp; cpp++) 
                    krb5_xfree(*cpp);
@@ -74,6 +76,8 @@ krb__get_srvtabname(default_srvtabname)
                return retname;
            }
        }
+       if (retname != NULL)
+           free(retname);
        retname = strdup(default_srvtabname);
        return retname;
 }