ACK: [PATCH] acpi: s3: fix two memory leaks on fwts_get() calls and minor clean-ups

ivanhu ivan.hu at canonical.com
Fri May 31 07:04:15 UTC 2019


On 5/20/19 4:21 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Currently the two calls to fwts_get leak the data they fetch. Fix this
> by only calling fwts_get once and free'ing the string.  Also split
> overly wide commend line.
>
> Addresses-Coverity: ("Resource leak")
> Fixes: 6b94bb6a4b13 ("acpi: s3: check sleep type for output messages")
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>  src/acpi/s3/s3.c | 18 +++++++++++++-----
>  1 file changed, 13 insertions(+), 5 deletions(-)
>
> diff --git a/src/acpi/s3/s3.c b/src/acpi/s3/s3.c
> index ff25960f..87e9fd97 100644
> --- a/src/acpi/s3/s3.c
> +++ b/src/acpi/s3/s3.c
> @@ -52,7 +52,12 @@ static char *s3_hook = NULL;		/* Hook to run after each S3 */
>  
>  static int s3_init(fwts_framework *fw)
>  {
> -	/* Pre-init - make sure wakealarm works so that we can wake up after suspend */
> +	char *str;
> +
> +	/*
> +	 *  Pre-init - make sure wakealarm works so that we can
> +	 *  wake up after suspend
> +	 */
>  	if (fwts_wakealarm_test_firing(fw, 1) != FWTS_OK) {
>  		fwts_log_error(fw, "Cannot automatically wake machine up - aborting Sleep test.");
>  		fwts_failed(fw, LOG_LEVEL_MEDIUM, "BadWakeAlarmSleep",
> @@ -60,10 +65,13 @@ static int s3_init(fwts_framework *fw)
>  		return FWTS_ERROR;
>  	}
>  
> -	if (fwts_get(PM_SUPEND_PATH) != NULL && strstr(fwts_get(PM_SUPEND_PATH), "[s2idle]"))
> -		strncpy(sleep_type, "s2idle", strlen("s2idle") + 1);
> -	else
> -		strncpy(sleep_type, "S3", strlen("S3") + 1);
> +	str = fwts_get(PM_SUPEND_PATH);
> +	if (str && strstr(str, "[s2idle]")) {
> +		strncpy(sleep_type, "s2idle", strlen("s2idle") + 1);
> +		free(str);
> +	} else {
> +		strncpy(sleep_type, "S3", strlen("S3") + 1);
> +	}
>  
>  	return FWTS_OK;
>  }

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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/fwts-devel/attachments/20190531/e8623762/attachment.sig>


More information about the fwts-devel mailing list