diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c index ea9e06f5..ccb2a26a 100644 --- a/gatchat/gatchat.c +++ b/gatchat/gatchat.c @@ -171,13 +171,11 @@ static struct at_command *at_command_create(const char *cmd, } c = g_try_new0(struct at_command, 1); - if (!c) return 0; len = strlen(cmd); c->cmd = g_try_new(char, len + 2); - if (!c->cmd) { g_free(c); return 0; @@ -612,7 +610,6 @@ static char *extract_line(GAtChat *p) } line = g_try_new(char, line_length + 1); - if (!line) { ring_buffer_drain(p->buf, p->read_so_far); return NULL; @@ -905,7 +902,6 @@ static GAtChat *create_chat(GIOChannel *channel, GIOFlags flags, return NULL; chat = g_try_new0(GAtChat, 1); - if (!chat) return chat; @@ -1200,7 +1196,6 @@ static struct at_notify *at_notify_create(GAtChat *chat, const char *prefix, return 0; notify = g_try_new0(struct at_notify, 1); - if (!notify) { g_free(key); return 0; @@ -1239,7 +1234,6 @@ guint g_at_chat_register(GAtChat *chat, const char *prefix, return 0; node = g_try_new0(struct at_notify_node, 1); - if (!node) return 0; diff --git a/gatchat/gatmux.c b/gatchat/gatmux.c index 3902956d..44d2ee8c 100644 --- a/gatchat/gatmux.c +++ b/gatchat/gatmux.c @@ -539,7 +539,7 @@ GAtMux *g_at_mux_new(GIOChannel *channel, const GAtMuxDriver *driver) if (!channel) return NULL; - mux = g_new0(GAtMux, 1); + mux = g_try_new0(GAtMux, 1); if (!mux) return NULL; diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c index 839ebe4d..1e445b2a 100644 --- a/gatchat/gatserver.c +++ b/gatchat/gatserver.c @@ -813,7 +813,6 @@ static char *extract_line(GAtServer *p) line_length -= 3; line = g_try_new(char, line_length + 1); - if (!line) { ring_buffer_drain(p->read_buf, p->read_so_far); return NULL; diff --git a/gatchat/ringbuffer.c b/gatchat/ringbuffer.c index 42d5b680..23bcaed7 100644 --- a/gatchat/ringbuffer.c +++ b/gatchat/ringbuffer.c @@ -43,13 +43,11 @@ struct ring_buffer *ring_buffer_new(unsigned int size) if (real_size > MAX_SIZE) return NULL; - buffer = g_new(struct ring_buffer, 1); - + buffer = g_try_new(struct ring_buffer, 1); if (!buffer) return NULL; - buffer->buffer = g_new(unsigned char, real_size); - + buffer->buffer = g_try_new(unsigned char, real_size); if (!buffer->buffer) { g_free(buffer); return NULL;