shithub: riscv

Download patch

ref: d5f2d2cc3fc7c2d3701e906df5d2d53781c4ee9c
parent: dfec09c436a8a328fc97007cf2dc3cd5476cc748
author: cinap_lenrek <[email protected]>
date: Tue Sep 25 16:15:24 EDT 2018

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

--- a/sys/src/cmd/webfs/fns.h
+++ b/sys/src/cmd/webfs/fns.h
@@ -25,10 +25,6 @@
 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);
--- a/sys/src/cmd/webfs/mkfile
+++ b/sys/src/cmd/webfs/mkfile
@@ -3,6 +3,6 @@
 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
--- a/sys/src/cmd/webfs/url.c
+++ b/sys/src/cmd/webfs/url.c
@@ -73,15 +73,12 @@
 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;
 }