Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/backends/sentry_backend_breakpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,10 @@ extern "C" {
sentry_backend_t *
sentry__backend_new(void)
{
auto *backend = SENTRY_MAKE(sentry_backend_t);
auto *backend = SENTRY_MAKE_0(sentry_backend_t);
if (!backend) {
return nullptr;
}
memset(backend, 0, sizeof(sentry_backend_t));

backend->startup_func = breakpad_backend_startup;
backend->shutdown_func = breakpad_backend_shutdown;
Expand Down
3 changes: 1 addition & 2 deletions src/backends/sentry_backend_crashpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,11 +1041,10 @@ crashpad_backend_remove_attachment(
sentry_backend_t *
sentry__backend_new(void)
{
auto *backend = SENTRY_MAKE(sentry_backend_t);
auto *backend = SENTRY_MAKE_0(sentry_backend_t);
if (!backend) {
return nullptr;
}
memset(backend, 0, sizeof(sentry_backend_t));

auto *data = new (std::nothrow) crashpad_state_t {};
if (!data) {
Expand Down
3 changes: 1 addition & 2 deletions src/backends/sentry_backend_inproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1686,11 +1686,10 @@ handle_except(sentry_backend_t *UNUSED(backend), const sentry_ucontext_t *uctx)
sentry_backend_t *
sentry__backend_new(void)
{
sentry_backend_t *backend = SENTRY_MAKE(sentry_backend_t);
sentry_backend_t *backend = SENTRY_MAKE_0(sentry_backend_t);
if (!backend) {
return NULL;
}
memset(backend, 0, sizeof(sentry_backend_t));

backend->startup_func = startup_inproc_backend;
backend->shutdown_func = shutdown_inproc_backend;
Expand Down
14 changes: 14 additions & 0 deletions src/sentry_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ sentry_malloc(size_t size)
return malloc(size);
}

void *
sentry__calloc(size_t count, size_t size)
{
#ifdef WITH_PAGE_ALLOCATOR
if (sentry__page_allocator_enabled()) {
// the page allocator is a bump allocator backed by mmap(MAP_ANONYMOUS),
// which the OS guarantees to be zeroed on first use, and the page
// allocator never reuses freed allocations
return sentry__page_allocator_alloc(count * size);
}
#endif
return calloc(count, size);
}

void
sentry_free(void *ptr)
{
Expand Down
6 changes: 6 additions & 0 deletions src/sentry_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@
*/
#define SENTRY_MAKE(Type) (Type *)sentry_malloc(sizeof(Type))

/**
* This is a typed `calloc` that zero-initializes the allocation.
*/
void *sentry__calloc(size_t count, size_t size);
#define SENTRY_MAKE_0(Type) (Type *)sentry__calloc(1, sizeof(Type))

#endif
9 changes: 3 additions & 6 deletions src/sentry_attachment.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ sentry__attachment_from_path(sentry_path_t *path)
if (!path) {
return NULL;
}
sentry_attachment_t *attachment = SENTRY_MAKE(sentry_attachment_t);
sentry_attachment_t *attachment = SENTRY_MAKE_0(sentry_attachment_t);
if (!attachment) {
sentry__path_free(path);
return NULL;
}
memset(attachment, 0, sizeof(sentry_attachment_t));
attachment->path = path;
return attachment;
}
Expand All @@ -95,12 +94,11 @@ sentry__attachment_from_buffer(
sentry__path_free(filename);
return NULL;
}
sentry_attachment_t *attachment = SENTRY_MAKE(sentry_attachment_t);
sentry_attachment_t *attachment = SENTRY_MAKE_0(sentry_attachment_t);
if (!attachment) {
sentry__path_free(filename);
return NULL;
}
memset(attachment, 0, sizeof(sentry_attachment_t));
attachment->filename = filename;
attachment->buf = sentry_malloc(buf_len * sizeof(char));
memcpy(attachment->buf, buf, buf_len * sizeof(char));
Expand Down Expand Up @@ -216,11 +214,10 @@ attachment_clone(const sentry_attachment_t *attachment)
return NULL;
}

sentry_attachment_t *clone = SENTRY_MAKE(sentry_attachment_t);
sentry_attachment_t *clone = SENTRY_MAKE_0(sentry_attachment_t);
if (!clone) {
return NULL;
}
memset(clone, 0, sizeof(sentry_attachment_t));

if (attachment->path) {
clone->path = sentry__path_clone(attachment->path);
Expand Down
3 changes: 1 addition & 2 deletions src/sentry_hint.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
sentry_hint_t *
sentry_hint_new(void)
{
sentry_hint_t *hint = SENTRY_MAKE(sentry_hint_t);
sentry_hint_t *hint = SENTRY_MAKE_0(sentry_hint_t);
if (!hint) {
return NULL;
}
memset(hint, 0, sizeof(sentry_hint_t));
return hint;
}

Expand Down
3 changes: 1 addition & 2 deletions src/sentry_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
sentry_options_t *
sentry_options_new(void)
{
sentry_options_t *opts = SENTRY_MAKE(sentry_options_t);
sentry_options_t *opts = SENTRY_MAKE_0(sentry_options_t);
if (!opts) {
return NULL;
}
memset(opts, 0, sizeof(sentry_options_t));
opts->database_path = sentry__path_from_str(".sentry-native");
// we assume the DSN to be ASCII only
sentry_options_set_dsn(opts, getenv("SENTRY_DSN"));
Expand Down
4 changes: 2 additions & 2 deletions src/sentry_scope.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ get_client_sdk(void)
static void
init_scope(sentry_scope_t *scope)
{
memset(scope, 0, sizeof(sentry_scope_t));
scope->transaction = NULL;
scope->fingerprint = sentry_value_new_null();
scope->user = sentry_value_new_null();
Expand All @@ -94,6 +93,7 @@ get_scope(void)
return &g_scope;
}

memset(&g_scope, 0, sizeof(sentry_scope_t));
init_scope(&g_scope);
sentry_value_set_by_key(g_scope.contexts, "os", sentry__get_os_context());
g_scope.client_sdk = get_client_sdk();
Expand Down Expand Up @@ -165,7 +165,7 @@ sentry__scope_flush_unlock(void)
sentry_scope_t *
sentry_local_scope_new(void)
{
sentry_scope_t *scope = SENTRY_MAKE(sentry_scope_t);
sentry_scope_t *scope = SENTRY_MAKE_0(sentry_scope_t);
if (!scope) {
return NULL;
}
Expand Down
7 changes: 2 additions & 5 deletions src/sentry_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,13 @@ struct sentry_bgworker_s {
sentry_bgworker_t *
sentry__bgworker_new(void *state, void (*free_state)(void *state))
{
sentry_bgworker_t *bgw = SENTRY_MAKE(sentry_bgworker_t);
sentry_bgworker_t *bgw = SENTRY_MAKE_0(sentry_bgworker_t);
if (!bgw) {
if (free_state) {
free_state(state);
}
return NULL;
}
memset(bgw, 0, sizeof(sentry_bgworker_t));
sentry__thread_init(&bgw->thread_id);
sentry__mutex_init(&bgw->task_lock);
sentry__cond_init(&bgw->submit_signal);
Expand Down Expand Up @@ -364,12 +363,10 @@ sentry__bgworker_flush(sentry_bgworker_t *bgw, uint64_t timeout)
}
SENTRY_DEBUG("flushing background worker thread");

sentry_flush_task_t *flush_task
= sentry_malloc(sizeof(sentry_flush_task_t));
sentry_flush_task_t *flush_task = SENTRY_MAKE_0(sentry_flush_task_t);
if (!flush_task) {
return 1;
}
memset(flush_task, 0, sizeof(sentry_flush_task_t));
flush_task->refcount = 2; // this thread + background worker
flush_task->was_flushed = false;
sentry__cond_init(&flush_task->signal);
Expand Down
3 changes: 1 addition & 2 deletions src/sentry_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@ sentry_transport_t *
sentry_transport_new(
void (*send_func)(sentry_envelope_t *envelope, void *state))
{
sentry_transport_t *transport = SENTRY_MAKE(sentry_transport_t);
sentry_transport_t *transport = SENTRY_MAKE_0(sentry_transport_t);
if (!transport) {
return NULL;
}
memset(transport, 0, sizeof(sentry_transport_t));
transport->send_envelope_func = send_func;

return transport;
Expand Down
3 changes: 1 addition & 2 deletions src/sentry_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,10 @@ sentry__dsn_new_n(const char *raw_dsn, size_t raw_dsn_len)
// org_id is u64 in relay, so needs 20 characters + null termination
char org_id[21] = "";

sentry_dsn_t *dsn = SENTRY_MAKE(sentry_dsn_t);
sentry_dsn_t *dsn = SENTRY_MAKE_0(sentry_dsn_t);
if (!dsn) {
return NULL;
}
memset(dsn, 0, sizeof(sentry_dsn_t));
dsn->refcount = 1;

dsn->raw = sentry__string_clone_n(raw_dsn, raw_dsn_len);
Expand Down
12 changes: 4 additions & 8 deletions src/sentry_value.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,9 +390,8 @@ sentry_value_new_string(const char *value)
sentry_value_t
sentry_value_new_list(void)
{
list_t *l = SENTRY_MAKE(list_t);
list_t *l = SENTRY_MAKE_0(list_t);
if (l) {
memset(l, 0, sizeof(list_t));
sentry_value_t rv = new_thing_value(l, THING_TYPE_LIST);
if (sentry_value_is_null(rv)) {
sentry_free(l);
Expand All @@ -406,9 +405,8 @@ sentry_value_new_list(void)
sentry_value_t
sentry__value_new_list_with_size(size_t size)
{
list_t *l = SENTRY_MAKE(list_t);
list_t *l = SENTRY_MAKE_0(list_t);
if (l) {
memset(l, 0, sizeof(list_t));
l->allocated = size;
if (size) {
l->items = sentry_malloc(sizeof(sentry_value_t) * size);
Expand All @@ -431,9 +429,8 @@ sentry__value_new_list_with_size(size_t size)
sentry_value_t
sentry_value_new_object(void)
{
obj_t *o = SENTRY_MAKE(obj_t);
obj_t *o = SENTRY_MAKE_0(obj_t);
if (o) {
memset(o, 0, sizeof(obj_t));
sentry_value_t rv = new_thing_value(o, THING_TYPE_OBJECT);
if (sentry_value_is_null(rv)) {
sentry_free(o);
Expand All @@ -447,9 +444,8 @@ sentry_value_new_object(void)
sentry_value_t
sentry__value_new_object_with_size(size_t size)
{
obj_t *o = SENTRY_MAKE(obj_t);
obj_t *o = SENTRY_MAKE_0(obj_t);
if (o) {
memset(o, 0, sizeof(obj_t));
o->allocated = size;
if (size) {
o->pairs = sentry_malloc(sizeof(obj_pair_t) * size);
Expand Down
3 changes: 1 addition & 2 deletions src/transports/sentry_http_transport.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,10 @@ http_transport_get_state(sentry_transport_t *transport)
sentry_transport_t *
sentry__http_transport_new(void *client, sentry_http_send_func_t send_func)
{
http_transport_state_t *state = SENTRY_MAKE(http_transport_state_t);
http_transport_state_t *state = SENTRY_MAKE_0(http_transport_state_t);
if (!state) {
return NULL;
}
memset(state, 0, sizeof(http_transport_state_t));
state->ratelimiter = sentry__rate_limiter_new();
state->client = client;
state->send_func = send_func;
Expand Down
3 changes: 1 addition & 2 deletions src/transports/sentry_http_transport_curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ typedef struct {
static curl_client_t *
curl_client_new(void)
{
curl_client_t *client = SENTRY_MAKE(curl_client_t);
curl_client_t *client = SENTRY_MAKE_0(curl_client_t);
if (!client) {
return NULL;
}
memset(client, 0, sizeof(curl_client_t));

#ifdef SENTRY_PLATFORM_NX
client->nx_state = sentry_nx_curl_state_new();
Expand Down
3 changes: 1 addition & 2 deletions src/transports/sentry_http_transport_winhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ typedef struct {
static winhttp_client_t *
winhttp_client_new(void)
{
winhttp_client_t *client = SENTRY_MAKE(winhttp_client_t);
winhttp_client_t *client = SENTRY_MAKE_0(winhttp_client_t);
if (!client) {
return NULL;
}
memset(client, 0, sizeof(winhttp_client_t));

return client;
}
Expand Down
Loading