[vlc-devel] [PATCH] darwin/dirs: validate rc of asprint()
David Fuhrmann
david.fuhrmann at gmail.com
Sat Apr 25 09:33:17 CEST 2015
Hello,
> Am 25.04.2015 um 02:09 schrieb Arjun Sreedharan <arjun024 at gmail.com>:
>
> When asprintf() fails, @path is undefined.
>
> Signed-off-by: Arjun Sreedharan <arjun024 at gmail.com>
> ---
> src/darwin/dirs.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/darwin/dirs.c b/src/darwin/dirs.c
> index 9c34cc5..7b6cedf 100644
> --- a/src/darwin/dirs.c
> +++ b/src/darwin/dirs.c
> @@ -82,9 +82,10 @@ char *config_GetLibDir (void)
> if (dladdr(system_Init, &info)) {
> char *incompletepath = strdup(dirname( (char *)info.dli_fname ));
> char *path = NULL;
> - asprintf(&path, "%s/"PACKAGE, incompletepath);
> + if(asprintf(&path, "%s/"PACKAGE, incompletepath) == -1)
> + path = NULL;
This is not needed. path is already NULL on error.
> free(incompletepath);
> - return path;
> + return (path != NULL) ? path : strdup (PKGLIBDIR);
asprintf failure typically means out of memory. In this case we are screwed anyway and it is probably not a good idea to allocate another bunch of memory in strdup.
What is the actual error you are trying to solve here?
Best regards,
David
More information about the vlc-devel
mailing list