diff options
author | Timo Dritschler <timo.dritschler@kit.edu> | 2014-11-26 18:34:30 +0100 |
---|---|---|
committer | Timo Dritschler <timo.dritschler@kit.edu> | 2014-11-26 18:34:30 +0100 |
commit | fcec7a701ef599c432f29f13ce82bfdb464d7ee7 (patch) | |
tree | 9fa90d66d713e283dc84fe15b4ced94636bb20a0 | |
parent | 8d6149084c6c66dc0514021264128bb2a2458930 (diff) | |
download | kiro-fcec7a701ef599c432f29f13ce82bfdb464d7ee7.tar.gz kiro-fcec7a701ef599c432f29f13ce82bfdb464d7ee7.tar.bz2 kiro-fcec7a701ef599c432f29f13ce82bfdb464d7ee7.tar.xz kiro-fcec7a701ef599c432f29f13ce82bfdb464d7ee7.zip |
Replaced all calls to malloc, calloc and free by their respective glib versions
-rw-r--r-- | src/kiro-client.c | 2 | ||||
-rw-r--r-- | src/kiro-server.c | 8 | ||||
-rw-r--r-- | src/kiro-trb.c | 12 |
3 files changed, 11 insertions, 11 deletions
diff --git a/src/kiro-client.c b/src/kiro-client.c index b561b7a..818c0c3 100644 --- a/src/kiro-client.c +++ b/src/kiro-client.c @@ -150,7 +150,7 @@ kiro_client_connect (KiroClient *self, const char *address, const char *port) } g_debug ("Route to server resolved"); - struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc (1, sizeof (struct kiro_connection_context)); + struct kiro_connection_context *ctx = (struct kiro_connection_context *)g_try_malloc (sizeof (struct kiro_connection_context)); if (!ctx) { g_critical ("Failed to create connection context (Out of memory?)"); diff --git a/src/kiro-server.c b/src/kiro-server.c index b35d1d5..3463c81 100644 --- a/src/kiro-server.c +++ b/src/kiro-server.c @@ -125,7 +125,7 @@ connect_client (struct rdma_cm_id *client) return -1; } - struct kiro_connection_context *ctx = (struct kiro_connection_context *)calloc (1, sizeof (struct kiro_connection_context)); + struct kiro_connection_context *ctx = (struct kiro_connection_context *)g_try_malloc0 (sizeof (struct kiro_connection_context)); if (!ctx) { g_critical ("Failed to create connection context"); @@ -168,7 +168,7 @@ static int welcome_client (struct rdma_cm_id *client, void *mem, size_t mem_size) { struct kiro_connection_context *ctx = (struct kiro_connection_context *) (client->context); - ctx->rdma_mr = (struct kiro_rdma_mem *)calloc (1, sizeof (struct kiro_rdma_mem)); + ctx->rdma_mr = (struct kiro_rdma_mem *)g_try_malloc0 (sizeof (struct kiro_rdma_mem)); if (!ctx->rdma_mr) { g_critical ("Failed to allocate RDMA Memory Container: %s", strerror (errno)); @@ -220,7 +220,7 @@ event_loop (void *self) if (0 <= rdma_get_cm_event (priv->ec, &active_event)) { //Disable cancellation to prevent undefined states during shutdown pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); - struct rdma_cm_event *ev = malloc (sizeof (*active_event)); + struct rdma_cm_event *ev = g_try_malloc (sizeof (*active_event)); if (!ev) { g_critical ("Unable to allocate memory for Event handling!"); @@ -268,7 +268,7 @@ event_loop (void *self) g_debug ("Connection closed successfully. %u connected clients remaining", g_list_length (priv->clients)); } - free (ev); + g_free (ev); } pthread_setcancelstate (PTHREAD_CANCEL_ENABLE, NULL); diff --git a/src/kiro-trb.c b/src/kiro-trb.c index 6a303d2..585e8e3 100644 --- a/src/kiro-trb.c +++ b/src/kiro-trb.c @@ -98,7 +98,7 @@ kiro_trb_finalize (GObject *object) KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self); if (priv->mem) - free (priv->mem); + g_free (priv->mem); G_OBJECT_CLASS (kiro_trb_parent_class)->finalize (object); } @@ -223,7 +223,7 @@ kiro_trb_purge (KiroTrb *self, gboolean free_memory) priv->element_size = 0; if (free_memory) - free (priv->mem); + g_free (priv->mem); priv->mem = NULL; } @@ -244,7 +244,7 @@ kiro_trb_reshape (KiroTrb *self, uint64_t element_size, uint64_t element_count) return -1; size_t new_size = (element_size * element_count) + sizeof (struct KiroTrbInfo); - void *newmem = malloc (new_size); + void *newmem = g_try_malloc0 (new_size); if (!newmem) return -1; @@ -333,7 +333,7 @@ kiro_trb_adopt (KiroTrb *self, void *buff_in) KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self); if (priv->mem) - free (priv->mem); + g_free (priv->mem); priv->mem = buff_in; priv->initialized = 1; @@ -346,7 +346,7 @@ kiro_trb_clone (KiroTrb *self, void *buff_in) { KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self); struct KiroTrbInfo *header = (struct KiroTrbInfo *)buff_in; - void *newmem = malloc (header->buffer_size_bytes); + void *newmem = g_try_malloc0 (header->buffer_size_bytes); if (!newmem) return -1; @@ -354,7 +354,7 @@ kiro_trb_clone (KiroTrb *self, void *buff_in) memcpy (newmem, buff_in, header->buffer_size_bytes); if (priv->mem) - free (priv->mem); + g_free (priv->mem); priv->mem = newmem; priv->initialized = 1; |