ACK: [PATCH] fwts_framework: ensure the string returned from fwts_arch_names is free'd
ivanhu
ivan.hu at canonical.com
Thu Apr 30 07:17:06 UTC 2020
On 4/24/20 9:48 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> The string returned from fwts_arch_names is currently leaking. Fix this
> by free'ing the returned object. To do so, the returned string can't be
> a const char* so remove the const too.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
> src/lib/include/fwts_arch.h | 2 +-
> src/lib/src/fwts_arch.c | 2 +-
> src/lib/src/fwts_framework.c | 6 ++++--
> 3 files changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/src/lib/include/fwts_arch.h b/src/lib/include/fwts_arch.h
> index 55f1110b..07ec48b1 100644
> --- a/src/lib/include/fwts_arch.h
> +++ b/src/lib/include/fwts_arch.h
> @@ -32,7 +32,7 @@ typedef enum {
>
> extern fwts_architecture fwts_arch_get_host(void);
> extern fwts_architecture fwts_arch_get_arch(const char *name);
> -extern const char *fwts_arch_names(void);
> +extern char *fwts_arch_names(void);
> extern const char *fwts_arch_get_name(const fwts_architecture arch);
>
> #endif
> diff --git a/src/lib/src/fwts_arch.c b/src/lib/src/fwts_arch.c
> index 27fce6b0..4c92e910 100644
> --- a/src/lib/src/fwts_arch.c
> +++ b/src/lib/src/fwts_arch.c
> @@ -69,7 +69,7 @@ fwts_architecture fwts_arch_get_arch(const char *name)
> return __fwts_arch_get_arch(name);
> }
>
> -const char *fwts_arch_names(void)
> +char *fwts_arch_names(void)
> {
> const struct fwts_arch_info *ptr;
> size_t len;
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index dc1e3642..e1e896bb 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -1157,8 +1157,10 @@ static int fwts_framework_an_parse(fwts_framework *fw, const char *arg)
> {
> fw->target_arch = fwts_arch_get_arch(arg);
> if (fw->target_arch == FWTS_ARCH_OTHER) {
> - fprintf(stderr, "--arch can be one of: %s\n",
> - fwts_arch_names());
> + char *names = fwts_arch_names();
> +
> + fprintf(stderr, "--arch can be one of: %s\n", names ? names : "<unknown>");
> + free(names);
> return FWTS_ERROR;
> }
>
>
Acked-by: Ivan Hu <ivan.hu at canonical.com>
More information about the fwts-devel
mailing list