/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "apr_general.h" #include "apr_pools.h" #include "apr_errno.h" #include "apr_file_io.h" #include #include #include #if APR_HAVE_UNISTD_H #include #endif #include "testutil.h" #define ALLOC_BYTES 1024 static apr_pool_t *pmain = NULL; static apr_pool_t *pchild = NULL; static void alloc_bytes(abts_case *tc, void *data) { int i; char *alloc; alloc = apr_palloc(pmain, ALLOC_BYTES); ABTS_PTR_NOTNULL(tc, alloc); for (i=0;i * ap_close_listeners -> ... -> apr_socket_close -> * apr_pool_cleanup_run. This appears to be safe with the current * pools implementation, though perhaps only by chance. If the code is * changed to break this, catch that here - the API can be clarified * and callers fixed. */ static apr_status_t dodgy_cleanup(void *data) { apr_pool_t *p = data; return apr_pool_cleanup_run(p, another_data, another_cleanup); } static void test_cleanups(abts_case *tc, void *data) { apr_status_t rv; int n; /* do this several times to test the cleanup freelist handling. */ for (n = 0; n < 5; n++) { apr_pool_cleanup_register(pchild, NULL, success_cleanup, success_cleanup); apr_pool_cleanup_register(pchild, checker_data, checker_cleanup, success_cleanup); apr_pool_cleanup_register(pchild, NULL, checker_cleanup, success_cleanup); apr_pool_cleanup_register(pchild, another_data, another_cleanup, another_cleanup); apr_pool_cleanup_register(pchild, pchild, dodgy_cleanup, dodgy_cleanup); rv = apr_pool_cleanup_run(p, NULL, success_cleanup); ABTS_ASSERT(tc, "nullop cleanup run OK", rv == APR_SUCCESS); rv = apr_pool_cleanup_run(p, checker_data, checker_cleanup); ABTS_ASSERT(tc, "cleanup passed correct data", rv == APR_SUCCESS); rv = apr_pool_cleanup_run(p, NULL, checker_cleanup); ABTS_ASSERT(tc, "cleanup passed correct data", rv == APR_EGENERAL); if (n == 2) { /* clear the pool to check that works */ apr_pool_clear(pchild); } if (n % 2 == 0) { /* throw another random cleanup into the mix */ apr_pool_cleanup_register(pchild, NULL, apr_pool_cleanup_null, apr_pool_cleanup_null); } } } static void test_tags(abts_case *tc, void *data) { /* if APR_POOL_DEBUG is set, all pools are tagged by default */ #if APR_POOL_DEBUG ABTS_PTR_NOTNULL(tc, apr_pool_get_tag(pmain)); #else ABTS_PTR_EQUAL(tc, NULL, apr_pool_get_tag(pmain)); #endif apr_pool_tag(pmain, "main pool"); ABTS_STR_EQUAL(tc, "main pool", apr_pool_get_tag(pmain)); } abts_suite *testpool(abts_suite *suite) { suite = ADD_SUITE(suite) abts_run_test(suite, parent_pool, NULL); abts_run_test(suite, child_pool, NULL); abts_run_test(suite, test_ancestor, NULL); abts_run_test(suite, test_notancestor, NULL); abts_run_test(suite, alloc_bytes, NULL); abts_run_test(suite, calloc_bytes, NULL); abts_run_test(suite, test_cleanups, NULL); abts_run_test(suite, test_tags, NULL); return suite; }