From: Greg Hudson Date: Fri, 9 Jul 2010 01:22:38 +0000 (+0000) Subject: Improve output variable handling of osa_adb_get_policy() in the db2 X-Git-Tag: krb5-1.9-beta1~152 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d9bf0b54f825b2b96c983cf4d812f2b7fe34873b;p=krb5.git Improve output variable handling of osa_adb_get_policy() in the db2 KDB module, and close some unlikely memory leaks. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24180 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/plugins/kdb/db2/adb_policy.c b/src/plugins/kdb/db2/adb_policy.c index 057f1826f..87fab3ac5 100644 --- a/src/plugins/kdb/db2/adb_policy.c +++ b/src/plugins/kdb/db2/adb_policy.c @@ -9,12 +9,10 @@ static char *rcsid = "$Header$"; #endif -#include -#include -#include "policy_db.h" -#include -#include -#include +#include "k5-int.h" + +#include +#include "policy_db.h" #define OPENLOCK(db, mode) \ { \ @@ -184,13 +182,14 @@ error: */ krb5_error_code osa_adb_get_policy(osa_adb_policy_t db, char *name, - osa_policy_ent_t *entry) + osa_policy_ent_t *entry_ptr) { DBT dbkey; DBT dbdata; XDR xdrs; int ret; - char *aligned_data; + char *aligned_data = NULL; + osa_policy_ent_t entry = NULL; OPENLOCK(db, KRB5_DB_LOCKMODE_SHARED); @@ -212,24 +211,26 @@ osa_adb_get_policy(osa_adb_policy_t db, char *name, ret = OSA_ADB_FAILURE; goto error; } - if (!(*(entry) = (osa_policy_ent_t)malloc(sizeof(osa_policy_ent_rec)))) { - ret = ENOMEM; + entry = k5alloc(sizeof(*entry), &ret); + if (entry == NULL) goto error; - } - if (!(aligned_data = (char *) malloc(dbdata.size))) { - ret = ENOMEM; + aligned_data = k5alloc(dbdata.size, &ret); + if (aligned_data == NULL) goto error; - } memcpy(aligned_data, dbdata.data, dbdata.size); - memset(*entry, 0, sizeof(osa_policy_ent_rec)); xdrmem_create(&xdrs, aligned_data, dbdata.size, XDR_DECODE); - if (!xdr_osa_policy_ent_rec(&xdrs, *entry)) - ret = OSA_ADB_FAILURE; - else ret = OSA_ADB_OK; + if (!xdr_osa_policy_ent_rec(&xdrs, entry)) { + ret = OSA_ADB_FAILURE; + goto error; + } + ret = OSA_ADB_OK; xdr_destroy(&xdrs); - free(aligned_data); + *entry_ptr = entry; + entry = NULL; error: + free(aligned_data); + free(entry); CLOSELOCK(db); return ret; }