Patchwork acpi: fan: fix resource leak bugs

login
register
mail settings
Submitter Colin King
Date May 6, 2013, 10:42 p.m.
Message ID <1367880171-19966-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/241810/
State Accepted
Headers show

Comments

Colin King - May 6, 2013, 10:42 p.m.
From: Colin Ian King <colin.king@canonical.com>

Coverity CID #997266, #997267 Resource leak.

close opened dir and free info on error return.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpi/fan/fan.c | 3 +++
 1 file changed, 3 insertions(+)
Alex Hung - May 7, 2013, 5:57 a.m.
On 05/07/2013 06:42 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997266, #997267 Resource leak.
>
> close opened dir and free info on error return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/fan/fan.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/src/acpi/fan/fan.c b/src/acpi/fan/fan.c
> index 586ec50..184da1a 100644
> --- a/src/acpi/fan/fan.c
> +++ b/src/acpi/fan/fan.c
> @@ -76,12 +76,15 @@ static fwts_list *get_fan_info(fwts_framework *fw)
>   			if (info == NULL) {
>   				fwts_log_error(fw, "Out of memory gathing fan information.");
>   				fwts_list_free(fans, free_fan_info);
> +				closedir(dir);
>   				return NULL;
>   			}
>
>   			if ((info->name = strdup(entry->d_name)) == NULL) {
>   				fwts_log_error(fw, "Out of memory gathing fan information.");
>   				fwts_list_free(fans, free_fan_info);
> +				free(info);
> +				closedir(dir);
>   				return NULL;
>   			}
>
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - May 16, 2013, 2:19 a.m.
On 05/07/2013 06:42 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997266, #997267 Resource leak.
>
> close opened dir and free info on error return.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/acpi/fan/fan.c | 3 +++
>   1 file changed, 3 insertions(+)
>
> diff --git a/src/acpi/fan/fan.c b/src/acpi/fan/fan.c
> index 586ec50..184da1a 100644
> --- a/src/acpi/fan/fan.c
> +++ b/src/acpi/fan/fan.c
> @@ -76,12 +76,15 @@ static fwts_list *get_fan_info(fwts_framework *fw)
>   			if (info == NULL) {
>   				fwts_log_error(fw, "Out of memory gathing fan information.");
>   				fwts_list_free(fans, free_fan_info);
> +				closedir(dir);
>   				return NULL;
>   			}
>
>   			if ((info->name = strdup(entry->d_name)) == NULL) {
>   				fwts_log_error(fw, "Out of memory gathing fan information.");
>   				fwts_list_free(fans, free_fan_info);
> +				free(info);
> +				closedir(dir);
>   				return NULL;
>   			}
>
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/acpi/fan/fan.c b/src/acpi/fan/fan.c
index 586ec50..184da1a 100644
--- a/src/acpi/fan/fan.c
+++ b/src/acpi/fan/fan.c
@@ -76,12 +76,15 @@  static fwts_list *get_fan_info(fwts_framework *fw)
 			if (info == NULL) {
 				fwts_log_error(fw, "Out of memory gathing fan information.");
 				fwts_list_free(fans, free_fan_info);
+				closedir(dir);
 				return NULL;
 			}
 
 			if ((info->name = strdup(entry->d_name)) == NULL) {
 				fwts_log_error(fw, "Out of memory gathing fan information.");
 				fwts_list_free(fans, free_fan_info);
+				free(info);
+				closedir(dir);
 				return NULL;
 			}