From: Nil Admirari <nil-admir...@mailo.com> --- This version has the advantage that duplicating the string is checked and that av_strdup(NULL) (whose behaviour is undocumented) is avoided.
Here is a branch complete with these changes: https://github.com/mkver/FFmpeg/commits/getenv The Windows version has not been tested. libavfilter/vf_frei0r.c | 20 ++++++++++++++++---- libavutil/getenv_utf8.h | 12 ++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c index f11ae6e55c..46b4175ba2 100644 --- a/libavfilter/vf_frei0r.c +++ b/libavfilter/vf_frei0r.c @@ -31,6 +31,7 @@ #include "libavutil/avstring.h" #include "libavutil/common.h" #include "libavutil/eval.h" +#include "libavutil/getenv_utf8.h" #include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" @@ -204,13 +205,19 @@ static av_cold int frei0r_init(AVFilterContext *ctx, } /* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */ - if ((path = av_strdup(getenv("FREI0R_PATH")))) { + path = getenv_utf8("FREI0R_PATH"); + if (path) { #ifdef _WIN32 const char *separator = ";"; #else const char *separator = ":"; #endif char *p, *ptr = NULL; + + path = getenv_make_writable(path); + if (!path) + return AVERROR(ENOMEM); + for (p = path; p = av_strtok(p, separator, &ptr); p = NULL) { /* add additional trailing slash in case it is missing */ char *p1 = av_asprintf("%s/", p); @@ -231,12 +238,17 @@ static av_cold int frei0r_init(AVFilterContext *ctx, if (ret < 0) return ret; } - if (!s->dl_handle && (path = getenv("HOME"))) { + if (!s->dl_handle && (path = getenv_utf8("HOME"))) { char *prefix = av_asprintf("%s/.frei0r-1/lib/", path); - if (!prefix) - return AVERROR(ENOMEM); + if (!prefix) { + ret = AVERROR(ENOMEM); + goto home_path_end; + } ret = load_path(ctx, &s->dl_handle, prefix, dl_name); av_free(prefix); + + home_path_end: + freeenv_utf8(path); if (ret < 0) return ret; } diff --git a/libavutil/getenv_utf8.h b/libavutil/getenv_utf8.h index 03d108eed4..37a778b7aa 100644 --- a/libavutil/getenv_utf8.h +++ b/libavutil/getenv_utf8.h @@ -59,6 +59,11 @@ static inline void freeenv_utf8(char *var) av_free(var); } +static inline char *getenv_make_writable(char *var) +{ + return var; +} + #else static inline char *getenv_utf8(const char *varname) @@ -70,6 +75,11 @@ static inline void freeenv_utf8(char *var) { } +static inline char *getenv_make_writable(const char *var) +{ + return av_strdup(var); +} + #endif // _WIN32 #else @@ -78,6 +88,8 @@ static inline void freeenv_utf8(char *var) #define freeenv_utf8(x) ((void) 0) +#define getenv_make_writable(x) NULL + #endif // HAVE_GETENV #endif // AVUTIL_GETENV_UTF8_H -- 2.34.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".