svn rev #24180: trunk/src/plugins/kdb/db2/

ghudson@MIT.EDU ghudson at MIT.EDU
Thu Jul 8 21:22:38 EDT 2010


http://src.mit.edu/fisheye/changelog/krb5/?cs=24180
Commit By: ghudson
Log Message:
Improve output variable handling of osa_adb_get_policy() in the db2
KDB module, and close some unlikely memory leaks.



Changed Files:
U   trunk/src/plugins/kdb/db2/adb_policy.c
Modified: trunk/src/plugins/kdb/db2/adb_policy.c
===================================================================
--- trunk/src/plugins/kdb/db2/adb_policy.c	2010-07-08 23:51:24 UTC (rev 24179)
+++ trunk/src/plugins/kdb/db2/adb_policy.c	2010-07-09 01:22:38 UTC (rev 24180)
@@ -9,13 +9,11 @@
 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)                                              \
     {                                                                   \
         int olret;                                                      \
@@ -184,13 +182,14 @@
  */
 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 @@
         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;
 }




More information about the cvs-krb5 mailing list