diff options
author | Craig Tiller <ctiller@google.com> | 2015-03-05 16:24:22 -0800 |
---|---|---|
committer | Craig Tiller <ctiller@google.com> | 2015-03-05 16:24:22 -0800 |
commit | 60fd3614807703218300a410bd437a5e950efbed (patch) | |
tree | 4fd612709c488269ee18c655c3f484763bdfb8da /src/core | |
parent | 8104988ce4bcce7d94eaef995928a9742cb69707 (diff) |
Crash in channel/server creation if grpc_init not called
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/surface/channel.c | 2 | ||||
-rw-r--r-- | src/core/surface/init.c | 10 | ||||
-rw-r--r-- | src/core/surface/init.h | 1 | ||||
-rw-r--r-- | src/core/surface/server.c | 4 |
4 files changed, 17 insertions, 0 deletions
diff --git a/src/core/surface/channel.c b/src/core/surface/channel.c index e38734c6a4..e764a3b9af 100644 --- a/src/core/surface/channel.c +++ b/src/core/surface/channel.c @@ -39,6 +39,7 @@ #include "src/core/iomgr/iomgr.h" #include "src/core/surface/call.h" #include "src/core/surface/client.h" +#include "src/core/surface/init.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> @@ -63,6 +64,7 @@ grpc_channel *grpc_channel_create_from_filters( size_t size = sizeof(grpc_channel) + grpc_channel_stack_size(filters, num_filters); grpc_channel *channel = gpr_malloc(size); + GPR_ASSERT(grpc_is_initialized() && "call grpc_init()"); channel->is_client = is_client; /* decremented by grpc_channel_destroy, and grpc_client_channel_closed if is_client */ gpr_ref_init(&channel->refs, 1 + is_client); diff --git a/src/core/surface/init.c b/src/core/surface/init.c index 4db66fb66e..1f5c8d1b5d 100644 --- a/src/core/surface/init.c +++ b/src/core/surface/init.c @@ -73,3 +73,13 @@ void grpc_shutdown(void) { } gpr_mu_unlock(&g_init_mu); } + +int grpc_is_initialized(void) { + int r; + gpr_once_init(&g_init, do_init); + gpr_mu_lock(&g_init_mu); + r = g_initializations > 0; + gpr_mu_unlock(&g_init_mu); + return r; +} + diff --git a/src/core/surface/init.h b/src/core/surface/init.h index ab40bedf87..416874020d 100644 --- a/src/core/surface/init.h +++ b/src/core/surface/init.h @@ -35,5 +35,6 @@ #define GRPC_INTERNAL_CORE_SURFACE_INIT_H void grpc_security_pre_init(void); +int grpc_is_initialized(void); #endif /* GRPC_INTERNAL_CORE_SURFACE_INIT_H */ diff --git a/src/core/surface/server.c b/src/core/surface/server.c index c99a1b4cc9..424734c54c 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -44,6 +44,7 @@ #include "src/core/surface/call.h" #include "src/core/surface/channel.h" #include "src/core/surface/completion_queue.h" +#include "src/core/surface/init.h" #include "src/core/transport/metadata.h" #include <grpc/support/alloc.h> #include <grpc/support/log.h> @@ -612,6 +613,9 @@ grpc_server *grpc_server_create_from_filters(grpc_completion_queue *cq, int census_enabled = grpc_channel_args_is_census_enabled(args); grpc_server *server = gpr_malloc(sizeof(grpc_server)); + + GPR_ASSERT(grpc_is_initialized() && "call grpc_init()"); + memset(server, 0, sizeof(grpc_server)); if (cq) addcq(server, cq); |