ACK: [PATCH] uefi: uefidump: free original string on failed realloc
ivanhu
ivan.hu at canonical.com
Fri Apr 21 02:40:16 UTC 2017
On 04/13/2017 06:08 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> A common bug is where realloc fails to allocate and we assume that
> the memory being realloc'd was freed. This is not the case, the
> NULL return means we need to free the original string to avoid
> a memory leak.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
> src/uefi/uefidump/uefidump.c | 8 ++++++--
> 1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/src/uefi/uefidump/uefidump.c b/src/uefi/uefidump/uefidump.c
> index 90556204..305d2d6a 100644
> --- a/src/uefi/uefidump/uefidump.c
> +++ b/src/uefi/uefidump/uefidump.c
> @@ -83,9 +83,13 @@ static char *uefidump_vprintf(char *str, const char *fmt, ...)
> if (str == NULL)
> str = strdup(buffer);
> else {
> - str = realloc(str, strlen(str) + strlen(buffer) + 1);
> - if (str == NULL)
> + char *tmp;
> + tmp = realloc(str, strlen(str) + strlen(buffer) + 1);
> + if (!tmp) {
> + free(str);
> return NULL;
> + }
> + str = tmp;
> strcat(str, buffer);
> }
>
>
Acked-by: Ivan Hu <ivan.hu at canonical.com>
More information about the fwts-devel
mailing list