From: Greg Hudson Date: Fri, 24 Jun 2016 16:33:05 +0000 (-0400) Subject: Fix memory leak in db2 policy DB initialization X-Git-Tag: krb5-1.15-beta1~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f53160634dd5de41c12701ade9e59d4b4dcd645b;p=thirdparty%2Fkrb5.git 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. ticket: 8432 (new) target_version: 1.14-next tags: pullup --- diff --git a/src/plugins/kdb/db2/adb_openclose.c b/src/plugins/kdb/db2/adb_openclose.c index d9d4cee3ec..7db30a33b0 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