]> git.alsa-project.org Git - alsa-gobject.git/commitdiff
rawmidi: skip check of return value from g_malloc()
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Mon, 16 Nov 2020 02:45:41 +0000 (11:45 +0900)
committer坂本 貴史 <o-takashi@sakamocchi.jp>
Mon, 16 Nov 2020 12:04:53 +0000 (21:04 +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/rawmidi/query.c

index 385dc123d10a3cfd140eb524357675df335e50d7..73c3ee011723def9db0cdf91eaf6a4554e74d7ad 100644 (file)
@@ -153,11 +153,8 @@ void alsarawmidi_get_device_id_list(guint card_id, guint **entries,
         goto end;
 
     length = strlen(PREFIX_SYSNAME_TEMPLATE) + calculate_digits(card_id) + 1;
-    prefix = g_try_malloc0(length);
-    if (prefix == NULL) {
-        generate_error(error, ENOMEM);
-        goto end;
-    }
+    prefix = g_malloc0(length);
+
     snprintf(prefix, length, PREFIX_SYSNAME_TEMPLATE, card_id);
 
     entry_list = udev_enumerate_get_list_entry(enumerator);
@@ -175,11 +172,7 @@ void alsarawmidi_get_device_id_list(guint card_id, guint **entries,
     if (count == 0)
         goto end;
 
-    *entries = g_try_malloc0_n(count, sizeof(**entries));
-    if (*entries == NULL) {
-        generate_error(error, ENOMEM);
-        goto end;
-    }
+    *entries = g_malloc0_n(count, sizeof(**entries));
 
     index = 0;
     udev_list_entry_foreach(entry, entry_list) {
@@ -233,11 +226,8 @@ void alsarawmidi_get_rawmidi_sysname(guint card_id, guint device_id,
 
     length = strlen(RAWMIDI_SYSNAME_TEMPLATE) + calculate_digits(card_id) +
              calculate_digits(device_id) + 1;
-    name = g_try_malloc0(length);
-    if (name == NULL) {
-        generate_error(error, ENOMEM);
-        return;
-    }
+    name = g_malloc0(length);
+
     snprintf(name, length, RAWMIDI_SYSNAME_TEMPLATE, card_id, device_id);
 
     ctx = udev_new();
@@ -281,11 +271,8 @@ void alsarawmidi_get_rawmidi_devnode(guint card_id, guint device_id,
 
     length = strlen(RAWMIDI_SYSNAME_TEMPLATE) + calculate_digits(card_id) +
              calculate_digits(device_id) + 1;
-    name = g_try_malloc0(length);
-    if (name == NULL) {
-        generate_error(error, ENOMEM);
-        return;
-    }
+    name = g_malloc0(length);
+
     snprintf(name, length, RAWMIDI_SYSNAME_TEMPLATE, card_id, device_id);
 
     ctx = udev_new();
@@ -304,13 +291,10 @@ void alsarawmidi_get_rawmidi_devnode(guint card_id, guint device_id,
     }
 
     node = udev_device_get_devnode(dev);
-    if (node == NULL) {
+    if (node == NULL)
         generate_error(error, ENOENT);
-    } else {
-        *devnode = strdup(node);
-        if (*devnode == NULL)
-            generate_error(error, ENOMEM);
-    }
+    else
+        *devnode = g_strdup(node);
 
     udev_device_unref(dev);
     udev_unref(ctx);
@@ -327,11 +311,8 @@ static void rawmidi_perform_ctl_ioctl(guint card_id, long request, void *data,
     int fd;
 
     length = strlen(CTL_SYSNAME_TEMPLATE) + calculate_digits(card_id) + 1;
-    sysname = g_try_malloc0(length);
-    if (sysname == NULL) {
-        generate_error(error, ENOMEM);
-        return;
-    }
+    sysname = g_malloc0(length);
+
     snprintf(sysname, length, CTL_SYSNAME_TEMPLATE, card_id);
 
     ctx = udev_new();
@@ -406,11 +387,7 @@ void alsarawmidi_get_subdevice_id_list(guint card, guint device,
     if (*error != NULL)
         return;
 
-    *entries = g_try_malloc0_n(info.subdevices_count, sizeof(guint));
-    if (*entries == NULL) {
-        generate_error(error, ENOMEM);
-        return;
-    }
+    *entries = g_malloc0_n(info.subdevices_count, sizeof(guint));
 
     for (i = 0; i < info.subdevices_count; ++i)
         (*entries)[i] = i;