jwoolley 02/04/09 21:31:11
Modified: mmap/unix mmap.c
mmap/win32 mmap.c
Log:
Fix a problem with the is_owner handling in the Unix and MMAP code that
would cause a cleanup to be killed that didn't exist in a certain set of
circumstances (create, dup but don't transfer ownership, dup again, delete
the second dup, boom). Also fix a potential problem in the Unix code where
the ->mm pointer would not be set to NULL if munmap failed. Logic like
that caused us headaches a while back in the directory cleanups.
Reviewed by: Greg Ames, William Rowe
Revision Changes Path
1.41 +9 -16 apr/mmap/unix/mmap.c
Index: mmap.c
===================================================================
RCS file: /home/cvs/apr/mmap/unix/mmap.c,v
retrieving revision 1.40
retrieving revision 1.41
diff -u -d -u -r1.40 -r1.41
--- mmap.c 13 Mar 2002 20:39:24 -0000 1.40
+++ mmap.c 10 Apr 2002 04:31:10 -0000 1.41
@@ -85,25 +85,21 @@
apr_mmap_t *mm = themmap;
int rv;
- if (!mm->is_owner) {
- return APR_SUCCESS;
+ if ((!mm->is_owner) || (mm->mm == (void *)-1)) {
+ /* XXX: we shouldn't ever get here */
+ return APR_ENOENT;
}
#ifdef BEOS
rv = delete_area(mm->area);
-
- if (rv == 0) {
- mm->mm = (void *)-1;
- return APR_SUCCESS;
- }
#else
rv = munmap(mm->mm, mm->size);
+#endif
+ mm->mm = (void *)-1;
if (rv == 0) {
- mm->mm = (void *)-1;
return APR_SUCCESS;
}
-#endif
return errno;
}
@@ -189,24 +185,21 @@
(*new_mmap)->is_owner = 1;
old_mmap->is_owner = 0;
apr_pool_cleanup_kill(old_mmap->cntxt, old_mmap, mmap_cleanup);
+ apr_pool_cleanup_register(p, *new_mmap, mmap_cleanup,
+ apr_pool_cleanup_null);
}
else {
(*new_mmap)->is_owner = 0;
}
- apr_pool_cleanup_register(p, *new_mmap, mmap_cleanup,
- apr_pool_cleanup_null);
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_mmap_delete(apr_mmap_t *mm)
{
- apr_status_t rv;
+ apr_status_t rv = APR_SUCCESS;
- if (mm->mm == (void *)-1)
- return APR_ENOENT;
-
- if ((rv = mmap_cleanup(mm)) == APR_SUCCESS) {
+ if (mm->is_owner && ((rv = mmap_cleanup(mm)) == APR_SUCCESS)) {
apr_pool_cleanup_kill(mm->cntxt, mm, mmap_cleanup);
return APR_SUCCESS;
}
1.12 +7 -6 apr/mmap/win32/mmap.c
Index: mmap.c
===================================================================
RCS file: /home/cvs/apr/mmap/win32/mmap.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -u -r1.11 -r1.12
--- mmap.c 13 Mar 2002 20:39:24 -0000 1.11
+++ mmap.c 10 Apr 2002 04:31:10 -0000 1.12
@@ -68,8 +68,9 @@
apr_mmap_t *mm = themmap;
apr_status_t rv = 0;
- if (!mm->is_owner) {
- return APR_SUCCESS;
+ if (!mm->is_owner || !mm->mhandle) {
+ /* XXX: we shouldn't ever get here */
+ return APR_ENOENT;
}
if (mm->mv) {
@@ -184,21 +185,21 @@
(*new_mmap)->is_owner = 1;
old_mmap->is_owner = 0;
apr_pool_cleanup_kill(old_mmap->cntxt, old_mmap, mmap_cleanup);
+ apr_pool_cleanup_register(p, *new_mmap, mmap_cleanup,
+ apr_pool_cleanup_null);
}
else {
(*new_mmap)->is_owner = 0;
}
- apr_pool_cleanup_register(p, *new_mmap, mmap_cleanup,
- apr_pool_cleanup_null);
}
return APR_SUCCESS;
}
APR_DECLARE(apr_status_t) apr_mmap_delete(apr_mmap_t *mm)
{
- apr_status_t rv;
+ apr_status_t rv = APR_SUCCESS;
- if ((rv = mmap_cleanup(mm)) == APR_SUCCESS) {
+ if (mm->is_owner && ((rv = mmap_cleanup(mm)) == APR_SUCCESS)) {
apr_pool_cleanup_kill(mm->cntxt, mm, mmap_cleanup);
return APR_SUCCESS;
}