diff options
author | Greg Hudson <ghudson@mit.edu> | 2016-06-24 12:33:05 -0400 |
---|---|---|
committer | Tom Yu <tlyu@mit.edu> | 2016-09-02 14:49:36 -0400 |
commit | f7d6382a135d76de1857d1db485354cbbb967d16 (patch) | |
tree | cd661b40370110996e91c81fe3b274046c32ccb4 | |
parent | 22a7aeab244cb5a2f262f45648ad504aa30a7d3f (diff) | |
download | krb5-f7d6382a135d76de1857d1db485354cbbb967d16.zip krb5-f7d6382a135d76de1857d1db485354cbbb967d16.tar.gz krb5-f7d6382a135d76de1857d1db485354cbbb967d16.tar.bz2 |
Fix memory leak in db2 policy DB initialization
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
-rw-r--r-- | src/plugins/kdb/db2/adb_openclose.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/plugins/kdb/db2/adb_openclose.c b/src/plugins/kdb/db2/adb_openclose.c index d9d4cee..7db30a3 100644 --- a/src/plugins/kdb/db2/adb_openclose.c +++ b/src/plugins/kdb/db2/adb_openclose.c @@ -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 |