]> 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)
committerGreg Hudson <ghudson@mit.edu>
Wed, 10 Aug 2016 17:36:47 +0000 (13:36 -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.

ticket: 8432 (new)
target_version: 1.14-next
tags: pullup

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