From 576d96e1ce49fe97bee1500167a2d29c927f3004 Mon Sep 17 00:00:00 2001 From: Takashi Sakamoto Date: Sun, 15 Nov 2020 11:54:07 +0900 Subject: [PATCH] seq: skip check of return value from g_malloc() In GLib implementation, the call of g_malloc() can bring program abort due to memory starvation. This is necessarily preferable because applications cannot handle the case and GLib has alternative APIs named 'try' to allow applications to handle the case. On the other hand, the memory starvation is system wide issue and it's hard for applications to solve the issue. It's reasonable for the implementation to have program abort somehow. Furthermore, the call of g_object_new() can bring program abort due to memory starvation. It's impossible for applications to handle the case. This commit skips check of return value from g_malloc(). Signed-off-by: Takashi Sakamoto --- src/seq/client-info.c | 7 ++----- src/seq/event-cntr.c | 13 +++---------- src/seq/query.c | 31 +++++++------------------------ src/seq/user-client.c | 6 +----- 4 files changed, 13 insertions(+), 44 deletions(-) diff --git a/src/seq/client-info.c b/src/seq/client-info.c index d53ce43..e804a8c 100644 --- a/src/seq/client-info.c +++ b/src/seq/client-info.c @@ -283,11 +283,8 @@ void alsaseq_client_info_get_event_filter(ALSASeqClientInfo *self, return; } - *event_types = g_try_malloc0_n(count, sizeof(*event_types)); - if (*event_types == NULL) { - generate_error(error, ENOMEM); - return; - } + *event_types = g_malloc0_n(count, sizeof(*event_types)); + *event_type_count = count; index = 0; diff --git a/src/seq/event-cntr.c b/src/seq/event-cntr.c index a917e39..82bd0cb 100644 --- a/src/seq/event-cntr.c +++ b/src/seq/event-cntr.c @@ -99,11 +99,8 @@ ALSASeqEventCntr *alsaseq_event_cntr_new(guint count, GError **error) int i; priv->length = sizeof(struct snd_seq_event) * count; - priv->buf = g_try_malloc0(priv->length); - if (priv->buf == NULL) { - generate_error(error, ENOMEM); - return NULL; - } + priv->buf = g_malloc0(priv->length); + priv->allocated = TRUE; ev = (struct snd_seq_event *)priv->buf; @@ -888,11 +885,7 @@ static void ensure_variable_length_event(ALSASeqEventCntrPrivate *priv, to_tail = priv->length - (next_ev - priv->buf); - new = g_try_malloc(from_head + size + to_tail); - if (new == NULL) { - generate_error(error, ENOMEM); - return; - } + new = g_malloc(from_head + size + to_tail); memcpy(new, priv->buf, from_head); memcpy(new + from_head, data, size); diff --git a/src/seq/query.c b/src/seq/query.c index 203b9bf..ae938a7 100644 --- a/src/seq/query.c +++ b/src/seq/query.c @@ -60,9 +60,7 @@ void alsaseq_get_seq_sysname(gchar **sysname, GError **error) return; } - *sysname = strdup(name); - if (*sysname == NULL) - generate_error(error, ENOMEM); + *sysname = g_strdup(name); udev_device_unref(dev); udev_unref(ctx); @@ -104,9 +102,7 @@ void alsaseq_get_seq_devnode(gchar **devnode, GError **error) return; } - *devnode = strdup(node); - if (*devnode == NULL) - generate_error(error, ENOMEM); + *devnode = g_strdup(node); udev_device_unref(dev); udev_unref(ctx); @@ -215,12 +211,8 @@ void alsaseq_get_client_id_list(guint8 **entries, gsize *entry_count, return; } - list = g_try_malloc0_n(count, sizeof(guint)); - if (list == NULL) { - *entry_count = 0; - close(fd); - return; - } + list = g_malloc0_n(count, sizeof(guint)); + index = 0; client_info.client = -1; @@ -339,12 +331,8 @@ void alsaseq_get_port_id_list(guint8 client_id, guint8 **entries, } count = client_info.num_ports; - list = g_try_malloc0_n(count, sizeof(*list)); - if (list == NULL) { - generate_error(error, ENOMEM); - close(fd); - return; - } + list = g_malloc0_n(count, sizeof(*list)); + index = 0; port_info.addr.client = client_id; @@ -603,12 +591,7 @@ void alsaseq_get_queue_id_list(guint8 **entries, gsize *entry_count, return; } - list = g_try_malloc0_n(count, sizeof(*entries)); - if (list == NULL) { - generate_error(error, ENOMEM); - close(fd); - return; - } + list = g_malloc0_n(count, sizeof(*entries)); index = 0; for (i = 0; i < maximum_count; ++i) { diff --git a/src/seq/user-client.c b/src/seq/user-client.c index 1337cd5..b7df3d6 100644 --- a/src/seq/user-client.c +++ b/src/seq/user-client.c @@ -583,11 +583,7 @@ void alsaseq_user_client_create_source(ALSASeqUserClient *self, return; } - buf = g_try_malloc0(page_size); - if (buf == NULL) { - generate_error(error, ENOMEM); - return; - } + buf = g_malloc0(page_size); *gsrc = g_source_new(&funcs, sizeof(*src)); src = (UserClientSource *)(*gsrc); -- 2.47.3