]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
timer: skip check of return value from g_malloc()
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Sat, 14 Nov 2020 08:28:09 +0000 (17:28 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Sun, 15 Nov 2020 00:19:56 +0000 (09:19 +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/timer/instance-params.c
src/timer/query.c
src/timer/user-instance.c

index 42020c4cb97d90c4950264861916f9c9035b75bc..f1b7912e62682ad752d08e1f5d5d732009291bea 100644 (file)
@@ -209,11 +209,7 @@ void alsatimer_instance_params_get_event_filter(ALSATimerInstanceParams *self,
     if (count == 0)
         return;
 
-    list = g_try_malloc0_n(count, sizeof(*list));
-    if (list == NULL) {
-        generate_error(error, ENOMEM);
-        return;
-    }
+    list = g_malloc0_n(count, sizeof(*list));
 
     index = 0;
     for (i = 0; i < sizeof(filter) * 8; ++i) {
index a06cfb6688187445431af1444329cb6e5e156318..62419a43185a1205924264b5baa5ae36e89ec85e 100644 (file)
@@ -71,11 +71,7 @@ void alsatimer_get_sysname(char **sysname, GError **error)
 
     g_return_if_fail(sysname != NULL);
 
-    name = strdup(TIMER_SYSNAME_TEMPLATE);
-    if (name == NULL) {
-        generate_error(error, ENOMEM);
-        return;
-    }
+    name = g_strdup(TIMER_SYSNAME_TEMPLATE);
 
     if (!check_existence(name, error)) {
         g_free(name);
@@ -118,7 +114,7 @@ void alsatimer_get_devnode(char **devnode, GError **error)
 
     node = udev_device_get_devnode(dev);
     if (node != NULL)
-        *devnode = strdup(node);
+        *devnode = g_strdup(node);
     else
         generate_error(error, ENODEV);
 
@@ -371,11 +367,7 @@ void alsatimer_get_tstamp_source(int *clock_id, GError **error)
     // For codes of sign and new line.
     size += 2;
 
-    buf = g_try_malloc0(size);
-    if (buf == NULL) {
-        generate_error(error, ENOMEM);
-        return;
-    }
+    buf = g_malloc0(size);
 
     timer_get_node_param_value("timer_tstamp_monotonic", buf, size, &val,
                                error);
index f6b4cfb392a043f0c4d0198c8cf56a2718dd49f4..45f35241fcf1a35cc374ff86ba2eeccd542fd5f1 100644 (file)
@@ -476,11 +476,7 @@ void alsatimer_user_instance_create_source(ALSATimerUserInstance *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(TimerUserInstanceSource));
     src = (TimerUserInstanceSource *)(*gsrc);