libnet: Fix Coverity ID 1634803 Dereference after null check
[samba4-gss.git] / source3 / lib / global_contexts.c
blob4e3bbabfffe86745d7e27cb77b32a48e502f4a1b
1 /*
2 Unix SMB/CIFS implementation.
3 Global contexts
5 Copyright (C) Simo Sorce <idra@samba.org> 2010
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "replace.h"
23 #include "global_contexts.h"
24 #include <tevent.h>
25 #include "lib/util/fault.h"
26 #include "lib/util/samba_util.h"
27 #include "messages.h"
29 static struct tevent_context *global_event_ctx = NULL;
31 struct tevent_context *global_event_context(void)
33 if (!global_event_ctx) {
35 * Note we MUST use the NULL context here, not the
36 * autofree context, to avoid side effects in forked
37 * children exiting.
39 global_event_ctx = samba_tevent_context_init(NULL);
41 if (!global_event_ctx) {
42 smb_panic("Could not init global event context");
44 return global_event_ctx;
47 void global_event_context_free(void)
49 TALLOC_FREE(global_event_ctx);
52 static struct messaging_context *global_msg_ctx = NULL;
54 struct messaging_context *global_messaging_context(void)
56 if (global_msg_ctx == NULL) {
58 * Note we MUST use the NULL context here, not the
59 * autofree context, to avoid side effects in forked
60 * children exiting.
62 global_msg_ctx = messaging_init(NULL,
63 global_event_context());
65 return global_msg_ctx;
68 void global_messaging_context_free(void)
70 TALLOC_FREE(global_msg_ctx);