Fix a segfault in the DBD testcase when the DBD modules were not present.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr-util/trunk@692751 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES b/CHANGES
index 50fc91c..89a99bd 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes with APR-util 1.4.0
 
+  *) Fix a segfault in the DBD testcase when the DBD modules were not present.
+     [Graham Leggett]
+
   *) Add DTrace Probes to Hooks, making it easier to inspect APR Hook based
      applications with DTrace. [Theo Schlossnagle <jesus omniti.com>]
 
diff --git a/test/testdbd.c b/test/testdbd.c
index e7d1642..682599e 100644
--- a/test/testdbd.c
+++ b/test/testdbd.c
@@ -31,7 +31,7 @@
 }
 
 #if APU_HAVE_SQLITE2 || APU_HAVE_SQLITE3
-static void test_statement(abts_case *tc, apr_dbd_t* handle, 
+static void test_statement(abts_case *tc, apr_dbd_t* handle,
                            const apr_dbd_driver_t* driver, const char* sql)
 {
     int nrows;
@@ -42,7 +42,7 @@
     ABTS_ASSERT(tc, sql, rv == APR_SUCCESS);
 }
 
-static void create_table(abts_case *tc, apr_dbd_t* handle, 
+static void create_table(abts_case *tc, apr_dbd_t* handle,
                          const apr_dbd_driver_t* driver)
 {
     const char *sql = "CREATE TABLE apr_dbd_test ("
@@ -53,14 +53,14 @@
     test_statement(tc, handle, driver, sql);
 }
 
-static void drop_table(abts_case *tc, apr_dbd_t* handle, 
+static void drop_table(abts_case *tc, apr_dbd_t* handle,
                        const apr_dbd_driver_t* driver)
 {
     const char *sql = "DROP TABLE apr_dbd_test";
     test_statement(tc, handle, driver, sql);
 }
 
-static void delete_rows(abts_case *tc, apr_dbd_t* handle, 
+static void delete_rows(abts_case *tc, apr_dbd_t* handle,
                         const apr_dbd_driver_t* driver)
 {
     const char *sql = "DELETE FROM apr_dbd_test";
@@ -68,7 +68,7 @@
 }
 
 
-static void insert_data(abts_case *tc, apr_dbd_t* handle, 
+static void insert_data(abts_case *tc, apr_dbd_t* handle,
                         const apr_dbd_driver_t* driver, int count)
 {
     apr_pool_t* pool = p;
@@ -86,7 +86,7 @@
     }
 }
 
-static void select_rows(abts_case *tc, apr_dbd_t* handle, 
+static void select_rows(abts_case *tc, apr_dbd_t* handle,
                         const apr_dbd_driver_t* driver, int count)
 {
     apr_status_t rv;
@@ -144,7 +144,7 @@
   ABTS_STR_EQUAL(tc, "foo''bar", escaped);
 }
 
-static void test_dbd_generic(abts_case *tc, apr_dbd_t* handle, 
+static void test_dbd_generic(abts_case *tc, apr_dbd_t* handle,
                              const apr_dbd_driver_t* driver)
 {
     void* native;
@@ -182,12 +182,18 @@
     rv = apr_dbd_get_driver(pool, "sqlite2", &driver);
     ABTS_ASSERT(tc, "failed to fetch driver", rv == APR_SUCCESS);
     ABTS_PTR_NOTNULL(tc, driver);
+    if (!driver) {
+    	return;
+    }
 
     ABTS_STR_EQUAL(tc, "sqlite2", apr_dbd_name(driver));
 
     rv = apr_dbd_open(driver, pool, "data/sqlite2.db:600", &handle);
     ABTS_ASSERT(tc, "failed to open database", rv == APR_SUCCESS);
     ABTS_PTR_NOTNULL(tc, handle);
+    if (!handle) {
+    	return;
+    }
 
     test_dbd_generic(tc, handle, driver);
 }
@@ -204,12 +210,18 @@
     rv = apr_dbd_get_driver(pool, "sqlite3", &driver);
     ABTS_ASSERT(tc, "failed to fetch driver", rv == APR_SUCCESS);
     ABTS_PTR_NOTNULL(tc, driver);
+    if (!driver) {
+    	return;
+    }
 
     ABTS_STR_EQUAL(tc, "sqlite3", apr_dbd_name(driver));
 
     rv = apr_dbd_open(driver, pool, "data/sqlite3.db", &handle);
     ABTS_ASSERT(tc, "failed to open database", rv == APR_SUCCESS);
     ABTS_PTR_NOTNULL(tc, handle);
+    if (!handle) {
+    	return;
+    }
 
     test_dbd_generic(tc, handle, driver);
 }