Fix some cases where g_try_new should be used
authorMarcel Holtmann <marcel@holtmann.org>
Sat, 3 Apr 2010 02:20:53 +0000 (19:20 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Sat, 3 Apr 2010 02:20:53 +0000 (19:20 -0700)
gatchat/gatchat.c
gatchat/gatmux.c
gatchat/gatserver.c
gatchat/ringbuffer.c

index ea9e06f..ccb2a26 100644 (file)
@@ -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;
 
index 3902956..44d2ee8 100644 (file)
@@ -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;
 
index 839ebe4..1e445b2 100644 (file)
@@ -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;
index 42d5b68..23bcaed 100644 (file)
@@ -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;