ref: 18bf5ea941fc12c2239a4ef21abd091d6588ba0b
parent: e67dbadba1e3de20b08f9362b5503ae99e52daf4
author: phil9 <[email protected]>
date: Fri Apr 2 13:38:31 EDT 2021
reuse plumber send descriptor / fix memory leak (thanks kvik)
--- a/vdir.c
+++ b/vdir.c
@@ -46,6 +46,7 @@
int lineh;
int nlines;
int offset;
+int plumbfd;
void
showerrstr(void)
@@ -181,15 +182,10 @@
void
plumbfile(char *path, char *name)
{
- int fd;
char *f;
f = smprint("%s/%s", path, name);
- fd = plumbopen("send", OWRITE|OCEXEC);
- if(fd<0)
- return;
- plumbsendtext(fd, "vdir", nil, nil, f);
- close(fd);
+ plumbsendtext(plumbfd, "vdir", nil, nil, f);
free(f);
}
@@ -445,6 +441,9 @@
getwd(path, sizeof path);
if(argc==2)
snprint(path, sizeof path, abspath(path, argv[1]));
+ plumbfd = plumbopen("send", OWRITE|OCEXEC);
+ if(plumbfd<0)
+ sysfatal("plumbopen: %r");
readhome();
loaddirs();
if(initdraw(nil, nil, "vdir")<0)