]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
seq: skip check of return value from g_malloc()
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 15 Nov 2020 02:54:07 +0000 (11:54 +0900)
committerTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sun, 15 Nov 2020 02:54:07 +0000 (11:54 +0900)
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 <o-takashi@sakamocchi.jp>
src/seq/client-info.c
src/seq/event-cntr.c
src/seq/query.c
src/seq/user-client.c

index d53ce43cb1e1b817289890b12560a209e6603dc6..e804a8c7b95ca01808835169472aa5cdaa75e703 100644 (file)
@@ -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;
index a917e39df9b31e239c4679daf9156ba86740823e..82bd0cb007212b8fc405378ab4f302f2e0808b5b 100644 (file)
@@ -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);
index 203b9bff64ab1a423cf327edc71782985ece3fa5..ae938a73fd33fd6bb7375ed5881759a4e11a135e 100644 (file)
@@ -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) {
index 1337cd50640944bedc4f12155c77904658eff8ec..b7df3d62a37305d6ef9679925bfc0ae9f5c07ea2 100644 (file)
@@ -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);