diff --git a/libyasm/file.c b/libyasm/file.c index 10f73fdf..f558695a 100644 --- a/libyasm/file.c +++ b/libyasm/file.c @@ -422,7 +422,10 @@ yasm_fopen_include(const char *iname, const char *from, const char *mode, combine = yasm__combpath(from, iname); f = fopen(combine, mode); if (f) { - *oname = combine; + if (oname) + *oname = combine; + else + yasm_xfree(combine); return f; } yasm_xfree(combine); @@ -432,12 +435,17 @@ yasm_fopen_include(const char *iname, const char *from, const char *mode, combine = yasm__combpath(np->path, iname); f = fopen(combine, mode); if (f) { - *oname = combine; + if (oname) + *oname = combine; + else + yasm_xfree(combine); return f; } yasm_xfree(combine); } + if (oname) + *oname = NULL; return NULL; } diff --git a/libyasm/file.h b/libyasm/file.h index f37062d0..d81061d2 100644 --- a/libyasm/file.h +++ b/libyasm/file.h @@ -182,12 +182,13 @@ char *yasm__combpath_win(const char *from, const char *to); * \param iname file to include * \param from file doing the including * \param mode fopen mode string - * \param oname full pathname of included file (may be relative) + * \param oname full pathname of included file (may be relative). NULL + * may be passed if this is unwanted. * \return fopen'ed include file, or NULL if not found. */ -/*@null@*/ FILE *yasm_fopen_include(const char *iname, const char *from, - const char *mode, - /*@out@*/ /*@only@*/ char **oname); +/*@null@*/ FILE *yasm_fopen_include + (const char *iname, const char *from, const char *mode, + /*@null@*/ /*@out@*/ /*@only@*/ char **oname); /** Delete any stored include paths added by yasm_add_include_path(). */