Commit e3c8a232 authored by Witold Krecicki's avatar Witold Krecicki
Browse files

Merge branch 'wpk-crash-on-mutex-init-failure' into 'master'

isc_mutex_init and isc_condition_init failures are now fatal

See merge request !1049
parents ac4f8a51 929ea7c2
Pipeline #7119 failed with stages
in 10 minutes and 22 seconds
5099. [func] Failed mutex and conditional creations are always
fatal. [GL #674]
--- 9.13.4 released ---
 
5098. [func] Failed memory allocations are now fatal. [GL #674]
......
......@@ -1390,8 +1390,7 @@ setup_libs(void) {
isc_mempool_setfreemax(commctx, 6);
isc_mempool_setfillcount(commctx, 2);
result = isc_mutex_init(&lookup_lock);
check_result(result, "isc_mutex_init");
isc_mutex_init(&lookup_lock);
}
typedef struct dig_ednsoptname {
......@@ -4199,7 +4198,7 @@ destroy_libs(void) {
}
UNLOCK_LOOKUP;
DESTROYLOCK(&lookup_lock);
isc_mutex_destroy(&lookup_lock);
debug("Removing log context");
isc_log_destroy(&lctx);
......
......@@ -3874,9 +3874,11 @@ main(int argc, char *argv[]) {
isc_result_totext(result));
}
RUNTIME_CHECK(isc_mutex_init(&namelock) == ISC_R_SUCCESS);
if (printstats)
RUNTIME_CHECK(isc_mutex_init(&statslock) == ISC_R_SUCCESS);
isc_mutex_init(&namelock);
if (printstats) {
isc_mutex_init(&statslock);
}
presign();
TIME_NOW(&sign_start);
......@@ -3934,9 +3936,9 @@ main(int argc, char *argv[]) {
check_result(result, "dns_master_dumptostream3");
}
DESTROYLOCK(&namelock);
isc_mutex_destroy(&namelock);
if (printstats)
DESTROYLOCK(&statslock);
isc_mutex_destroy(&statslock);
if (!output_stdout) {
result = isc_stdio_close(outfp);
......
......@@ -9615,8 +9615,8 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) {
&server->in_roothints),
"setting up root hints");
CHECKFATAL(isc_mutex_init(&server->reload_event_lock),
"initializing reload event lock");
isc_mutex_init(&server->reload_event_lock);
server->reload_event =
isc_event_allocate(named_g_mctx, server,
NAMED_EVENT_RELOAD,
......
......@@ -3226,7 +3226,7 @@ destroy_listener(void *arg) {
/* We don't have to acquire the lock here since it's already unlinked */
dns_acl_detach(&listener->acl);
DESTROYLOCK(&listener->lock);
isc_mutex_destroy(&listener->lock);
isc_mem_putanddetach(&listener->mctx, listener, sizeof(*listener));
}
......@@ -3253,11 +3253,7 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp,
listener->mctx = NULL;
ISC_LINK_INIT(listener, link);
result = isc_mutex_init(&listener->lock);
if (result != ISC_R_SUCCESS) {
isc_mem_put(server->mctx, listener, sizeof(*listener));
return (ISC_R_FAILURE);
}
isc_mutex_init(&listener->lock);
isc_mem_attach(server->mctx, &listener->mctx);
......@@ -3352,7 +3348,7 @@ cleanup:
if (result != ISC_R_SUCCESS) {
if (listener->acl != NULL)
dns_acl_detach(&listener->acl);
DESTROYLOCK(&listener->lock);
isc_mutex_destroy(&listener->lock);
isc_mem_putanddetach(&listener->mctx, listener,
sizeof(*listener));
}
......
......@@ -252,9 +252,7 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
}
/* Initialize the lock */
result = isc_mutex_init(&cd->lock);
if (result != ISC_R_SUCCESS)
goto failed;
isc_mutex_init(&cd->lock);
/* Open the library */
dlopen_flags = RTLD_NOW|RTLD_GLOBAL;
......@@ -364,15 +362,19 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
failed:
dlopen_log(ISC_LOG_ERROR, "dlz_dlopen of '%s' failed", dlzname);
if (cd->dl_path != NULL)
if (cd->dl_path != NULL) {
isc_mem_free(mctx, cd->dl_path);
if (cd->dlzname != NULL)
}
if (cd->dlzname != NULL) {
isc_mem_free(mctx, cd->dlzname);
if (dlopen_flags != 0)
(void) isc_mutex_destroy(&cd->lock);
}
if (dlopen_flags != 0) {
isc_mutex_destroy(&cd->lock);
}
#ifdef HAVE_DLCLOSE
if (cd->dl_handle)
if (cd->dl_handle) {
dlclose(cd->dl_handle);
}
#endif
isc_mem_put(mctx, cd, sizeof(*cd));
isc_mem_destroy(&mctx);
......@@ -395,17 +397,20 @@ dlopen_dlz_destroy(void *driverarg, void *dbdata) {
MAYBE_UNLOCK(cd);
}
if (cd->dl_path)
if (cd->dl_path) {
isc_mem_free(cd->mctx, cd->dl_path);
if (cd->dlzname)
}
if (cd->dlzname) {
isc_mem_free(cd->mctx, cd->dlzname);
}
#ifdef HAVE_DLCLOSE
if (cd->dl_handle)
if (cd->dl_handle) {
dlclose(cd->dl_handle);
}
#endif
(void) isc_mutex_destroy(&cd->lock);
isc_mutex_destroy(&cd->lock);
mctx = cd->mctx;
isc_mem_put(mctx, cd, sizeof(*cd));
......
......@@ -253,9 +253,7 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
triedload = true;
/* Initialize the lock */
result = isc_mutex_init(&cd->lock);
if (result != ISC_R_SUCCESS)
goto failed;
isc_mutex_init(&cd->lock);
/* Open the library */
cd->dl_handle = LoadLibraryA(cd->dl_path);
......@@ -349,17 +347,21 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
return (ISC_R_SUCCESS);
cleanup_lock:
DESTROYLOCK(&cd->lock);
isc_mutex_destroy(&cd->lock);
failed:
dlopen_log(ISC_LOG_ERROR, "dlz_dlopen of '%s' failed", dlzname);
if (cd->dl_path)
if (cd->dl_path) {
isc_mem_free(mctx, cd->dl_path);
if (cd->dlzname)
}
if (cd->dlzname) {
isc_mem_free(mctx, cd->dlzname);
if (triedload)
(void) isc_mutex_destroy(&cd->lock);
if (cd->dl_handle)
}
if (triedload) {
isc_mutex_destroy(&cd->lock);
}
if (cd->dl_handle) {
FreeLibrary(cd->dl_handle);
}
isc_mem_put(mctx, cd, sizeof(*cd));
isc_mem_destroy(&mctx);
return (result);
......@@ -390,7 +392,7 @@ dlopen_dlz_destroy(void *driverarg, void *dbdata) {
if (cd->dl_handle)
FreeLibrary(cd->dl_handle);
DESTROYLOCK(&cd->lock);
isc_mutex_destroy(&cd->lock);
mctx = cd->mctx;
isc_mem_put(mctx, cd, sizeof(*cd));
......
......@@ -290,8 +290,8 @@ main(int argc, char **argv) {
isc_stdtime_get(&now);
result = isc_mutex_init(&client_lock);
check_result(result, "isc_mutex_init(&client_lock)");
isc_mutex_init(&client_lock);
ISC_LIST_INIT(clients);
/*
......
......@@ -30,7 +30,7 @@ main(int argc, char *argv[]) {
isc_mem_debugging = ISC_MEM_DEBUGRECORD;
RUNTIME_CHECK(isc_mutex_init(&lock) == ISC_R_SUCCESS);
isc_mutex_init(&lock);
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
......@@ -114,7 +114,7 @@ main(int argc, char *argv[]) {
isc_mem_destroy(&mctx);
DESTROYLOCK(&lock);
isc_mutex_destroy(&lock);
return (0);
}
......@@ -206,7 +206,7 @@ main(int argc, char *argv[]) {
RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_mutex_init(&lock) == ISC_R_SUCCESS);
isc_mutex_init(&lock);
mctx = NULL;
RUNTIME_CHECK(isc_mem_create(0, 0, &mctx) == ISC_R_SUCCESS);
......@@ -282,7 +282,7 @@ main(int argc, char *argv[]) {
isc_mem_stats(mctx, stdout);
isc_mem_destroy(&mctx);
DESTROYLOCK(&lock);
isc_mutex_destroy(&lock);
isc_app_finish();
......
......@@ -35,7 +35,7 @@
/*
* Copyright (C) 1999-2001, 2016 Internet Systems Consortium, Inc. ("ISC")
*
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
......@@ -364,13 +364,7 @@ sdlzh_build_sqldbinstance(isc_mem_t *mctx, const char *allnodes_str,
isc_mem_attach(mctx, &db->mctx);
/* initialize the reference count mutex */
result = isc_mutex_init(&db->instance_lock);
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_mutex_init() failed: %s",
isc_result_totext(result));
goto cleanup;
}
isc_mutex_init(&db->instance_lock);
/* build the all nodes query list */
result = build_querylist(mctx, allnodes_str, &db->zone,
......
......@@ -498,7 +498,7 @@ static bool insecure_prefix_found;
static void
initialize_action(void) {
RUNTIME_CHECK(isc_mutex_init(&insecure_prefix_lock) == ISC_R_SUCCESS);
isc_mutex_init(&insecure_prefix_lock);
}
/*
......
......@@ -610,9 +610,7 @@ grow_entries(isc_task_t *task, isc_event_t *ev) {
/*
* Initialise the new resources.
*/
result = isc_mutexblock_init(newentrylocks, n);
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_mutexblock_init(newentrylocks, n);
for (i = 0; i < n; i++) {
ISC_LIST_INIT(newentries[i]);
......@@ -655,7 +653,7 @@ grow_entries(isc_task_t *task, isc_event_t *ev) {
/*
* Cleanup old resources.
*/
DESTROYMUTEXBLOCK(adb->entrylocks, adb->nentries);
isc_mutexblock_destroy(adb->entrylocks, adb->nentries);
isc_mem_put(adb->mctx, adb->entries,
sizeof(*adb->entries) * adb->nentries);
isc_mem_put(adb->mctx, adb->deadentries,
......@@ -767,9 +765,7 @@ grow_names(isc_task_t *task, isc_event_t *ev) {
/*
* Initialise the new resources.
*/
result = isc_mutexblock_init(newnamelocks, n);
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_mutexblock_init(newnamelocks, n);
for (i = 0; i < n; i++) {
ISC_LIST_INIT(newnames[i]);
......@@ -812,7 +808,7 @@ grow_names(isc_task_t *task, isc_event_t *ev) {
/*
* Cleanup old resources.
*/
DESTROYMUTEXBLOCK(adb->namelocks, adb->nnames);
isc_mutexblock_destroy(adb->namelocks, adb->nnames);
isc_mem_put(adb->mctx, adb->names,
sizeof(*adb->names) * adb->nnames);
isc_mem_put(adb->mctx, adb->deadnames,
......@@ -1895,7 +1891,6 @@ free_adbentry(dns_adb_t *adb, dns_adbentry_t **entry) {
static inline dns_adbfind_t *
new_adbfind(dns_adb_t *adb) {
dns_adbfind_t *h;
isc_result_t result;
h = isc_mempool_get(adb->ahmp);
if (h == NULL)
......@@ -1920,11 +1915,7 @@ new_adbfind(dns_adb_t *adb) {
/*
* private members
*/
result = isc_mutex_init(&h->lock);
if (result != ISC_R_SUCCESS) {
isc_mempool_put(adb->ahmp, h);
return (NULL);
}
isc_mutex_init(&h->lock);
ISC_EVENT_INIT(&h->event, sizeof(isc_event_t), 0, 0, 0, NULL, NULL,
NULL, NULL, h);
......@@ -1984,7 +1975,7 @@ free_adbfind(dns_adb_t *adb, dns_adbfind_t **findp) {
find->magic = 0;
DESTROYLOCK(&find->lock);
isc_mutex_destroy(&find->lock);
isc_mempool_put(adb->ahmp, find);
return (dec_adb_irefcnt(adb));
}
......@@ -2480,7 +2471,7 @@ destroy(dns_adb_t *adb) {
isc_mempool_destroy(&adb->aimp);
isc_mempool_destroy(&adb->afmp);
DESTROYMUTEXBLOCK(adb->entrylocks, adb->nentries);
isc_mutexblock_destroy(adb->entrylocks, adb->nentries);
isc_mem_put(adb->mctx, adb->entries,
sizeof(*adb->entries) * adb->nentries);
isc_mem_put(adb->mctx, adb->deadentries,
......@@ -2492,7 +2483,7 @@ destroy(dns_adb_t *adb) {
isc_mem_put(adb->mctx, adb->entry_refcnt,
sizeof(*adb->entry_refcnt) * adb->nentries);
DESTROYMUTEXBLOCK(adb->namelocks, adb->nnames);
isc_mutexblock_destroy(adb->namelocks, adb->nnames);
isc_mem_put(adb->mctx, adb->names,
sizeof(*adb->names) * adb->nnames);
isc_mem_put(adb->mctx, adb->deadnames,
......@@ -2504,12 +2495,12 @@ destroy(dns_adb_t *adb) {
isc_mem_put(adb->mctx, adb->name_refcnt,
sizeof(*adb->name_refcnt) * adb->nnames);
DESTROYLOCK(&adb->reflock);
DESTROYLOCK(&adb->lock);
DESTROYLOCK(&adb->mplock);
DESTROYLOCK(&adb->overmemlock);
DESTROYLOCK(&adb->entriescntlock);
DESTROYLOCK(&adb->namescntlock);
isc_mutex_destroy(&adb->reflock);
isc_mutex_destroy(&adb->lock);
isc_mutex_destroy(&adb->mplock);
isc_mutex_destroy(&adb->overmemlock);
isc_mutex_destroy(&adb->entriescntlock);
isc_mutex_destroy(&adb->namescntlock);
isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t));
}
......@@ -2606,29 +2597,12 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
isc_mem_attach(mem, &adb->mctx);
result = isc_mutex_init(&adb->lock);
if (result != ISC_R_SUCCESS)
goto fail0b;
result = isc_mutex_init(&adb->mplock);
if (result != ISC_R_SUCCESS)
goto fail0c;
result = isc_mutex_init(&adb->reflock);
if (result != ISC_R_SUCCESS)
goto fail0d;
result = isc_mutex_init(&adb->overmemlock);
if (result != ISC_R_SUCCESS)
goto fail0e;
result = isc_mutex_init(&adb->entriescntlock);
if (result != ISC_R_SUCCESS)
goto fail0f;
result = isc_mutex_init(&adb->namescntlock);
if (result != ISC_R_SUCCESS)
goto fail0g;
isc_mutex_init(&adb->lock);
isc_mutex_init(&adb->mplock);
isc_mutex_init(&adb->reflock);
isc_mutex_init(&adb->overmemlock);
isc_mutex_init(&adb->entriescntlock);
isc_mutex_init(&adb->namescntlock);
#define ALLOCENTRY(adb, el) \
do { \
......@@ -2666,9 +2640,8 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
* Initialize the bucket locks for names and elements.
* May as well initialize the list heads, too.
*/
result = isc_mutexblock_init(adb->namelocks, adb->nnames);
if (result != ISC_R_SUCCESS)
goto fail1;
isc_mutexblock_init(adb->namelocks, adb->nnames);
for (i = 0; i < adb->nnames; i++) {
ISC_LIST_INIT(adb->names[i]);
ISC_LIST_INIT(adb->deadnames[i]);
......@@ -2683,9 +2656,7 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
adb->entry_refcnt[i] = 0;
adb->irefcnt++;
}
result = isc_mutexblock_init(adb->entrylocks, adb->nentries);
if (result != ISC_R_SUCCESS)
goto fail2;
isc_mutexblock_init(adb->entrylocks, adb->nentries);
/*
* Memory pools
......@@ -2693,12 +2664,12 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
#define MPINIT(t, p, n) do { \
result = isc_mempool_create(mem, sizeof(t), &(p)); \
if (result != ISC_R_SUCCESS) \
goto fail3; \
goto fail2; \
isc_mempool_setfreemax((p), FREE_ITEMS); \
isc_mempool_setfillcount((p), FILL_COUNT); \
isc_mempool_setname((p), n); \
isc_mempool_associatelock((p), &adb->mplock); \
} while (0)
} while (0)
MPINIT(dns_adbname_t, adb->nmp, "adbname");
MPINIT(dns_adbnamehook_t, adb->nhmp, "adbnamehook");
......@@ -2715,13 +2686,13 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
*/
result = isc_task_create(adb->taskmgr, 0, &adb->task);
if (result != ISC_R_SUCCESS)
goto fail3;
goto fail2;
isc_task_setname(adb->task, "ADB", adb);
result = isc_stats_create(adb->mctx, &view->adbstats, dns_adbstats_max);
if (result != ISC_R_SUCCESS)
goto fail3;
goto fail2;
set_adbstat(adb, adb->nentries, dns_adbstats_nentries);
set_adbstat(adb, adb->nnames, dns_adbstats_nnames);
......@@ -2733,15 +2704,13 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
*newadb = adb;
return (ISC_R_SUCCESS);
fail3:
fail2:
if (adb->task != NULL)
isc_task_detach(&adb->task);
/* clean up entrylocks */
DESTROYMUTEXBLOCK(adb->entrylocks, adb->nentries);
fail2: /* clean up namelocks */
DESTROYMUTEXBLOCK(adb->namelocks, adb->nnames);
isc_mutexblock_destroy(adb->entrylocks, adb->nentries);
isc_mutexblock_destroy(adb->namelocks, adb->nnames);
fail1: /* clean up only allocated memory */
if (adb->entries != NULL)
......@@ -2789,18 +2758,12 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr,
if (adb->afmp != NULL)
isc_mempool_destroy(&adb->afmp);
DESTROYLOCK(&adb->namescntlock);
fail0g:
DESTROYLOCK(&adb->entriescntlock);
fail0f:
DESTROYLOCK(&adb->overmemlock);
fail0e:
DESTROYLOCK(&adb->reflock);
fail0d:
DESTROYLOCK(&adb->mplock);
fail0c:
DESTROYLOCK(&adb->lock);
fail0b:
isc_mutex_destroy(&adb->namescntlock);
isc_mutex_destroy(&adb->entriescntlock);
isc_mutex_destroy(&adb->overmemlock);
isc_mutex_destroy(&adb->reflock);
isc_mutex_destroy(&adb->mplock);
isc_mutex_destroy(&adb->lock);
if (adb->excl != NULL)
isc_task_detach(&adb->excl);
isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t));
......
......@@ -75,9 +75,7 @@ dns_badcache_init(isc_mem_t *mctx, unsigned int size, dns_badcache_t **bcp) {
memset(bc, 0, sizeof(dns_badcache_t));
isc_mem_attach(mctx, &bc->mctx);
result = isc_mutex_init(&bc->lock);
if (result != ISC_R_SUCCESS)
goto cleanup;
isc_mutex_init(&bc->lock);
bc->table = isc_mem_get(bc->mctx, sizeof(*bc->table) * size);
if (bc->table == NULL) {
......@@ -96,8 +94,7 @@ dns_badcache_init(isc_mem_t *mctx, unsigned int size, dns_badcache_t **bcp) {
return (ISC_R_SUCCESS);
destroy_lock:
DESTROYLOCK(&bc->lock);
cleanup:
isc_mutex_destroy(&bc->lock);
isc_mem_putanddetach(&bc->mctx, bc, sizeof(dns_badcache_t));
return (result);
}
......@@ -112,7 +109,7 @@ dns_badcache_destroy(dns_badcache_t **bcp) {
dns_badcache_flush(bc);
bc->magic = 0;
DESTROYLOCK(&bc->lock);
isc_mutex_destroy(&bc->lock);
isc_mem_put(bc->mctx, bc->table, sizeof(dns_bcentry_t *) * bc->size);
isc_mem_putanddetach(&bc->mctx, bc, sizeof(dns_badcache_t));
*bcp = NULL;
......
......@@ -224,9 +224,7 @@ dns_byaddr_create(isc_mem_t *mctx, const isc_netaddr_t *address,
byaddr->task = NULL;
isc_task_attach(task, &byaddr->task);
result = isc_mutex_init(&byaddr->lock);
if (result != ISC_R_SUCCESS)
goto cleanup_event;
isc_mutex_init(&byaddr->lock);
dns_fixedname_init(&byaddr->name);
......@@ -250,9 +248,8 @@ dns_byaddr_create(isc_mem_t *mctx, const isc_netaddr_t *address,
return (ISC_R_SUCCESS);
cleanup_lock:
DESTROYLOCK(&byaddr->lock);
isc_mutex_destroy(&byaddr->lock);
cleanup_event:
ievent = (isc_event_t *)byaddr->event;
isc_event_free(&ievent);
byaddr->event = NULL;
......@@ -291,7 +288,7 @@ dns_byaddr_destroy(dns_byaddr_t **byaddrp) {
REQUIRE(byaddr->task == NULL);
dns_lookup_destroy(&byaddr->lookup);
DESTROYLOCK(&byaddr->lock);
isc_mutex_destroy(&byaddr->lock);
byaddr->magic = 0;
isc_mem_putanddetach(&byaddr->mctx, byaddr, sizeof(*byaddr));
......
......@@ -212,13 +212,8 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
}
}
result = isc_mutex_init(&cache->lock);
if (result != ISC_R_SUCCESS)
goto cleanup_mem;
result = isc_mutex_init(&cache->filelock);
if (result != ISC_R_SUCCESS)
goto cleanup_lock;
isc_mutex_init(&cache->lock);
isc_mutex_init(&cache->filelock);
cache->references = 1;
cache->live_tasks = 0;
......@@ -313,26 +308,26 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr,
*cachep = cache;
return (ISC_R_SUCCESS);
cleanup_db:
cleanup_db:
dns_db_detach(&cache->db);
cleanup_dbargv:
cleanup_dbargv:
for (i = extra; i < cache->db_argc; i++)
if (cache->db_argv[i] != NULL)
isc_mem_free(cmctx, cache->db_argv[i]);
if (cache->db_argv != NULL)
isc_mem_put(cmctx, cache->db_argv,
cache->db_argc * sizeof(char *));
cleanup_dbtype: