From: Takashi Sakamoto Date: Sun, 15 Nov 2020 14:04:32 +0000 (+0900) Subject: hwdep: skip check of return value from g_malloc() X-Git-Tag: v0.1.99~33 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=24dbdf74242c98adfa1fdba29a60499bc97ea296;p=alsa-gobject.git hwdep: 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 --- diff --git a/src/hwdep/query.c b/src/hwdep/query.c index 4a8b807..daefd18 100644 --- a/src/hwdep/query.c +++ b/src/hwdep/query.c @@ -153,11 +153,8 @@ void alsahwdep_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 alsahwdep_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 alsahwdep_get_hwdep_sysname(guint card_id, guint device_id, length = strlen(HWDEP_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, HWDEP_SYSNAME_TEMPLATE, card_id, device_id); ctx = udev_new(); @@ -281,11 +271,8 @@ void alsahwdep_get_hwdep_devnode(guint card_id, guint device_id, length = strlen(HWDEP_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, HWDEP_SYSNAME_TEMPLATE, card_id, device_id); ctx = udev_new(); @@ -304,13 +291,10 @@ void alsahwdep_get_hwdep_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 hwdep_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();