diff --git a/base.c b/base.c index 95b77db..4cb4a00 100644 --- a/base.c +++ b/base.c @@ -186,8 +186,14 @@ void uio_free_info(struct uio_info_t* info) free (info->name); if (info->version) free (info->version); - if (info->maps) - free (info->maps); + if (info->maps) { + for (int i = 0; i < info->maxmap; i++) { + if (info->maps[i].name) { + free(info->maps[i].name); + } + } + free(info->maps); + } if (info->devname) free (info->devname); free (info); @@ -216,7 +222,6 @@ struct uio_info_t **uio_find_devices () info = calloc (nr, sizeof (struct uio_info_t *)); if (!info) { - errno = ENOMEM; g_warning (_("calloc: %s\n"), g_strerror (errno)); goto out; } @@ -263,7 +268,8 @@ struct uio_info_t *uio_find_by_uio_name (char *uio_name) if (!strcmp (name, uio_name)) { info = candidate; - break; + } else { + uio_free_info(candidate); } } free (uio_list); diff --git a/helper.c b/helper.c index 91c076b..809d6f5 100644 --- a/helper.c +++ b/helper.c @@ -293,8 +293,10 @@ struct uio_info_t *create_uio_info (char *dir, char *name) char filename [PATH_MAX]; info = calloc (1, sizeof (struct uio_info_t)); - if (!info) + if (!info) { + g_warning (_("calloc: %s\n"), g_strerror (errno)); return NULL; + } snprintf (filename, PATH_MAX, "%s/%s", dir, name); info->path = strdup (filename); diff --git a/libuio.h b/libuio.h index 36d7287..cd93875 100644 --- a/libuio.h +++ b/libuio.h @@ -35,6 +35,7 @@ extern "C" { struct uio_info_t; /* base functions */ +void uio_free_info(struct uio_info_t* info); struct uio_info_t **uio_find_devices (); struct uio_info_t *uio_find_by_uio_name (char *uio_name); struct uio_info_t *uio_find_by_uio_num (int num);