Index: trunk/psLib/src/db/psDB.c
===================================================================
--- trunk/psLib/src/db/psDB.c	(revision 9985)
+++ trunk/psLib/src/db/psDB.c	(revision 9990)
@@ -12,6 +12,6 @@
  *  @author Joshua Hoblitt
  *
- *  @version $Revision: 1.110 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-11-15 00:54:22 $
+ *  @version $Revision: 1.111 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-11-15 01:34:42 $
  *
  *  Copyright (C) 2005-2006  Joshua Hoblitt, University of Hawaii
@@ -68,4 +68,7 @@
 static psHash   *mysqlToSqlLookupTable = NULL;
 static psHash   *pTypeToMysqlLookupTable = NULL;
+
+// free func
+static void psDBFree(psDB *dbh);
 
 // database utility functions
@@ -120,9 +123,9 @@
 /*****************************************************************************/
 
-psDB *psDBInit(const char *host,
-               const char *user,
-               const char *passwd,
-               const char *dbname,
-               unsigned int port)
+psDB *psDBAlloc(const char *host,
+                const char *user,
+                const char *passwd,
+                const char *dbname,
+                unsigned int port)
 {
     MYSQL           *mysql;
@@ -180,4 +183,8 @@
     }
 
+    // don't set the deallocator func until after we've setup the lookup tables
+    // so an alloc error doesn't try to free potentionally uncreated tables
+    psMemSetDeallocator(dbh, (psFreeFunc) psDBFree);
+
     psTrace("psLib.db", PS_LOG_INFO, "connected to database %s", dbname);
 
@@ -185,5 +192,5 @@
 }
 
-void psDBCleanup(psDB *dbh)
+static void psDBFree(psDB *dbh)
 {
     // quietly handle NULLs
@@ -194,5 +201,4 @@
     // Attempt to close specified database connection
     mysql_close(dbh->mysql);
-    psFree(dbh);
 
     // ASC WARNING NOTE: the psDBSQLToPTypeTableCleanup cleanup routine
Index: trunk/psLib/src/db/psDB.h
===================================================================
--- trunk/psLib/src/db/psDB.h	(revision 9985)
+++ trunk/psLib/src/db/psDB.h	(revision 9990)
@@ -10,6 +10,6 @@
  *  @author Joshua Hoblitt
  *
- *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-10-13 22:26:14 $
+ *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-11-15 01:34:42 $
  *
  *  Copyright 2005 Joshua Hoblitt, University of Hawaii
@@ -40,7 +40,23 @@
 /** Opens a new database connection
  *
- *  @return psDB*:      A new psDB object if the database connection is successful or NULL on
- *  failure.
- */
+ *  @return psDB*:      A new psDB object if the database connection is
+ *  successful or NULL on failure.
+ */
+psDB *psDBAlloc(
+    const char *host,                  ///< Database server hostname
+    const char *user,                  ///< Database username
+    const char *passwd,                ///< Database password
+    const char *dbname,                ///< Database namespace
+    unsigned int port                  ///< Database port number
+);
+
+/** Opens a new database connection
+ *
+ *  This function is deprecated favor of psDBAlloc()
+ *
+ *  @return psDB*:      A new psDB object if the database connection is
+ *  successful or NULL on failure.
+ */
+#ifdef DOXYGEN
 psDB *psDBInit(
     const char *host,                  ///< Database server hostname
@@ -50,9 +66,21 @@
     unsigned int port                  ///< Database port number
 );
-
-/** Closes a database connection  */
+#else // DOXYGEN
+#define psDBInit(host, user, passwd, dbname, port) \
+psDBAlloc(host, user, passwd, dbname, port)
+#endif
+
+#ifdef DOXYGEN
+/** Closes a database connection
+ *
+ *  This function is deprecated favor of psFree()
+ */
 void psDBCleanup(
     psDB *dbh                          ///< Database handle
 );
+#else // DOXYGEN
+#define psDBCleanup(dbh) \
+psFree(dbh)
+#endif
 
 /** Creates a new database namespace
