testmmap: Avoid a crash after test_file_open() fails.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1920246 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/CHANGES b/CHANGES
index 800e811..5efe7b1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                      -*- coding: utf-8 -*-
 Changes for APR 2.0.0
 
+  *) testmmap: Avoid a crash after test_file_open() fails. [Graham
+     Leggett]
+
   *) apr_proc_mutex_timedlock() should return APR_TIMEUP on systems
      where semtimedop() returns ETIMEDOUT rather than
      EAGAIN. Likely AIX-only. [Eric Covener]
diff --git a/test/testmmap.c b/test/testmmap.c
index a548664..2a6f5cf 100644
--- a/test/testmmap.c
+++ b/test/testmmap.c
@@ -77,6 +77,11 @@
 {
     apr_status_t rv;
 
+    if (!thefile) {
+        ABTS_SKIP(tc, data, "File not open, skipping file close.");
+        return;
+    }
+
     rv = apr_file_close(thefile);
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
     thefile = NULL;
@@ -96,6 +101,11 @@
 {
     apr_status_t rv;
 
+    if (!thefile) {
+        ABTS_SKIP(tc, data, "File not open, skipping filesize test.");
+        return;
+    }
+
     rv = apr_file_info_get(&thisfinfo, APR_FINFO_NORM, thefile);
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
     ABTS_TRUE(tc, thisfinfo.size == (apr_off_t)(apr_size_t)thisfinfo.size);
@@ -111,6 +121,11 @@
     apr_size_t nbytes = 0;
     apr_status_t rv;
 
+    if (!thefile) {
+        ABTS_SKIP(tc, data, "File not open, skipping read.");
+        return;
+    }
+
     ABTS_TRUE(tc, *offset == (apr_off_t)(apr_size_t)*offset);
 
     rv = apr_file_read_full(thefile, thisfdata, thisfsize, &nbytes);
@@ -135,6 +150,11 @@
     apr_off_t *offset = data;
     apr_status_t rv;
 
+    if (!thefile) {
+        ABTS_SKIP(tc, data, "File not open, skipping mmap create.");
+        return;
+    }
+
     rv = apr_mmap_create(&themmap, thefile, *offset, thisfsize,
                          APR_MMAP_READ, ptest);
     ABTS_PTR_NOTNULL(tc, themmap);
@@ -144,21 +164,33 @@
 static void test_mmap_contents(abts_case *tc, void *data)
 {
     ABTS_PTR_NOTNULL(tc, themmap);
+
+    if (!themmap) {
+        ABTS_SKIP(tc, data, "MMap not open, skipping size comparison.");
+        return;
+    }
+
     ABTS_PTR_NOTNULL(tc, themmap->mm);
     ABTS_SIZE_EQUAL(tc, thisfsize, themmap->size);
 
     /* Must use nEquals since the string is not guaranteed to be NULL terminated */
     ABTS_STR_NEQUAL(tc, themmap->mm, thisfdata, thisfsize);
+
 }
 
 static void test_mmap_delete(abts_case *tc, void *data)
 {
     apr_status_t rv;
 
-    ABTS_PTR_NOTNULL(tc, themmap);
+    if (!themmap) {
+        ABTS_SKIP(tc, data, "MMap not open, skipping mmap delete.");
+        return;
+    }
+        
     rv = apr_mmap_delete(themmap);
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
     themmap = NULL;
+
 }
 
 static void test_mmap_offset(abts_case *tc, void *data)
@@ -166,12 +198,17 @@
     apr_status_t rv;
     void *addr;
 
-    ABTS_PTR_NOTNULL(tc, themmap);
+    if (!themmap) {
+        ABTS_SKIP(tc, data, "MMap not open, skipping mmap offset.");
+        return;
+    }    
+
     rv = apr_mmap_offset(&addr, themmap, 5);
 
     ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
     /* Must use nEquals since the string is not guaranteed to be NULL terminated */
     ABTS_STR_NEQUAL(tc, addr, thisfdata + 5, thisfsize - 5);
+
 }
 
 #endif