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
