From: Takashi Sakamoto Date: Sat, 14 Nov 2020 08:28:09 +0000 (+0900) Subject: timer: skip check of return value from g_malloc() X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=62570cc3254d9f18834517e268b6b22ee261fe19;p=alsa-gobject.git timer: 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/timer/instance-params.c b/src/timer/instance-params.c index 42020c4..f1b7912 100644 --- a/src/timer/instance-params.c +++ b/src/timer/instance-params.c @@ -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) { diff --git a/src/timer/query.c b/src/timer/query.c index a06cfb6..62419a4 100644 --- a/src/timer/query.c +++ b/src/timer/query.c @@ -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); diff --git a/src/timer/user-instance.c b/src/timer/user-instance.c index f6b4cfb..45f3524 100644 --- a/src/timer/user-instance.c +++ b/src/timer/user-instance.c @@ -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);