summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2010-07-09 01:22:38 +0000
committerGreg Hudson <ghudson@mit.edu>2010-07-09 01:22:38 +0000
commitd9bf0b54f825b2b96c983cf4d812f2b7fe34873b (patch)
tree8c1c76c4e0325ae5fe037743ad7329d05bd23158 /src
parent00b20720cc46f37347e5327aefba3128f3ece196 (diff)
downloadkrb5-d9bf0b54f825b2b96c983cf4d812f2b7fe34873b.tar.gz
krb5-d9bf0b54f825b2b96c983cf4d812f2b7fe34873b.tar.xz
krb5-d9bf0b54f825b2b96c983cf4d812f2b7fe34873b.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/plugins/kdb/db2/adb_policy.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/plugins/kdb/db2/adb_policy.c b/src/plugins/kdb/db2/adb_policy.c
index 057f1826ff..87fab3ac57 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 <sys/file.h>
-#include <fcntl.h>
-#include "policy_db.h"
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
+#include "k5-int.h"
+
+#include <sys/file.h>
+#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;
}