From: Takashi Sakamoto Date: Fri, 13 Nov 2020 07:26:26 +0000 (+0900) Subject: ctl: skip check of return value from g_malloc() X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=bcf512a3bfe4010b1d6633393f3687b42ada402b;p=alsa-gobject.git ctl: 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/ctl/card.c b/src/ctl/card.c index 0a49fbb..42534a2 100644 --- a/src/ctl/card.c +++ b/src/ctl/card.c @@ -289,11 +289,7 @@ static void allocate_elem_ids(int fd, struct snd_ctl_elem_list *list, return; // Allocate spaces for these elements. - ids = calloc(list->count, sizeof(*ids)); - if (!ids) { - generate_error(error, ENOMEM); - return; - } + ids = g_malloc_n(list->count, sizeof(*ids)); list->offset = 0; while (list->offset < list->count) { @@ -396,10 +392,6 @@ static void parse_enum_names(ALSACtlCardPrivate *priv, int i; *labels = g_malloc0_n(count + 1, sizeof(**labels)); - if (*labels == NULL) { - generate_error(error, ENOMEM); - return; - } for (i = 0; i < count; ++i) { info->value.enumerated.item = i; @@ -408,11 +400,7 @@ static void parse_enum_names(ALSACtlCardPrivate *priv, goto error; } - (*labels)[i] = strdup(info->value.enumerated.name); - if ((*labels)[i] == NULL) { - generate_error(error, ENOMEM); - goto error; - } + (*labels)[i] = g_strdup(info->value.enumerated.name); } (*labels)[count] = NULL; @@ -521,10 +509,6 @@ void alsactl_card_write_elem_tlv(ALSACtlCard *self, container_size = container_count * sizeof(*container); packet = g_malloc0(sizeof(*packet) + container_size); - if (packet == NULL) { - generate_error(error, ENOMEM); - return; - } packet->numid = elem_id->numid; packet->length = container_size; @@ -571,10 +555,6 @@ void alsactl_card_read_elem_tlv(ALSACtlCard *self, const ALSACtlElemId *elem_id, container_size = *container_count * sizeof(**container); packet = g_malloc0(sizeof(*packet) + container_size); - if (packet == NULL) { - generate_error(error, ENOMEM); - return; - } packet->numid = elem_id->numid; packet->length = container_size; @@ -624,10 +604,6 @@ void alsactl_card_command_elem_tlv(ALSACtlCard *self, container_size = *container_count * sizeof(**container); packet = g_malloc0(sizeof(*packet) + container_size); - if (packet == NULL) { - generate_error(error, ENOMEM); - return; - } packet->numid = elem_id->numid; packet->length = container_size; @@ -662,8 +638,7 @@ static int prepare_enum_names(struct snd_ctl_elem_info *info, const gchar **labe return -EINVAL; pos = g_malloc0(length); - if (pos == NULL) - return -ENOMEM; + info->value.enumerated.names_ptr = (__u64)pos; info->value.enumerated.names_length = length; @@ -1005,11 +980,7 @@ void alsactl_card_create_source(ALSACtlCard *self, GSource **gsrc, 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(CtlCardSource)); src = (CtlCardSource *)(*gsrc); diff --git a/src/ctl/query.c b/src/ctl/query.c index 889d989..4bec20d 100644 --- a/src/ctl/query.c +++ b/src/ctl/query.c @@ -147,11 +147,7 @@ void alsactl_get_card_id_list(guint **entries, gsize *entry_count, 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) { @@ -198,11 +194,7 @@ static void allocate_sysname(char **sysname ,const char *template, } length = strlen(template) + digits; - *sysname = g_try_malloc0(length + 1); - if (*sysname == NULL) { - generate_error(error, ENOMEM); - return; - } + *sysname = g_malloc0(length + 1); snprintf(*sysname, length, template, card_id); } @@ -332,7 +324,7 @@ void alsactl_get_control_devnode(guint card_id, 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);