]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Fix memory leak in db2 policy DB initialization
authorGreg Hudson <ghudson@mit.edu>
Fri, 24 Jun 2016 16:33:05 +0000 (12:33 -0400)
committerTom Yu <tlyu@mit.edu>
Fri, 2 Sep 2016 18:49:36 +0000 (14:49 -0400)
osa_adb_init_db() maintains a static linked list mapping filenames to
lock structures.  Entries are never removed from the list; when their
reference counts hit 0, the lockfile is closed but the filename
remains allocated.  However, the filename is allocated each time the
lockfile is re-opened, leaking the old value.  Fix this leak by moving
filename initialization to entry creation.

(cherry picked from commit f53160634dd5de41c12701ade9e59d4b4dcd645b)

ticket: 8432
version_fixed: 1.14.4

src/plugins/kdb/db2/adb_openclose.c

index d9d4cee3ec6937f6695ddf62fb3c8d76f823cf99..7db30a33b0cba79b758a3ce3994e50971d68ee3a 100644 (file)
@@ -131,6 +131,12 @@ osa_adb_init_db(osa_adb_db_t *dbp, char *filename, char *lockfilename,
             return ENOMEM;
         }
         memset(lockp, 0, sizeof(*lockp));
+        lockp->lockinfo.filename = strdup(lockfilename);
+        if (lockp->lockinfo.filename == NULL) {
+            free(lockp);
+            free(db);
+            return ENOMEM;
+        }
         lockp->next = locklist;
         locklist = lockp;
     }
@@ -146,7 +152,6 @@ osa_adb_init_db(osa_adb_db_t *dbp, char *filename, char *lockfilename,
          * needs be open read/write so that write locking can work with
          * POSIX systems
          */
-        lockp->lockinfo.filename = strdup(lockfilename);
         if ((lockp->lockinfo.lockfile = fopen(lockfilename, "r+")) == NULL) {
             /*
              * maybe someone took away write permission so we could only