webfs: fix memory leak in Nfmt(), use libc's new idn functions

This commit is contained in:
cinap_lenrek 2018-09-25 20:15:24 +02:00
parent dfec09c436
commit d5f2d2cc3f
3 changed files with 5 additions and 12 deletions

View file

@ -25,10 +25,6 @@ Url* saneurl(Url *u);
int matchurl(Url *u, Url *s);
void freeurl(Url *u);
/* idn */
char* idn2utf(char *name, char *buf, int nbuf);
char* utf2idn(char *name, char *buf, int nbuf);
/* buq */
int buread(Buq *q, void *v, int l);
int buwrite(Buq *q, void *v, int l);

View file

@ -3,6 +3,6 @@ BIN=/$objtype/bin
TARG=webfs
HFILES=fns.h dat.h
OFILES=sub.$O url.$O buq.$O http.$O fs.$O idn.$O
OFILES=sub.$O url.$O buq.$O http.$O fs.$O
</sys/src/cmd/mkone

View file

@ -73,15 +73,12 @@ Efmt(Fmt *f)
int
Nfmt(Fmt *f)
{
char *d, *s;
char d[Domlen], *s;
s = va_arg(f->args, char*);
d = emalloc(Domlen);
if(utf2idn(s, d, Domlen) == nil)
d = s;
fmtprint(f, "%s", d);
if(d != s)
free(d);
if(utf2idn(s, d, sizeof(d)) != nil)
s = d;
fmtprint(f, "%s", s);
return 0;
}