]> git.lizzy.rs Git - plan9front.git/commitdiff
vt: fix plumbsel(), snarfsel()
authorcinap_lenrek <cinap_lenrek@felloff.net>
Mon, 3 Sep 2018 18:54:26 +0000 (20:54 +0200)
committercinap_lenrek <cinap_lenrek@felloff.net>
Mon, 3 Sep 2018 18:54:26 +0000 (20:54 +0200)
- plumbsel()
- remove debug prints
- use smalloc() to convert to bytes
- fix spurious -1 close of plumb fd

- snarfsel()
- fix rune buffer leak in open error case

sys/src/cmd/vt/main.c

index 199ee84091c5724e58e58daee44ece828155b534..23a34a6ae8414b75f007ef0d8339faf6908af564 100644 (file)
@@ -958,38 +958,42 @@ snarfsel(void)
        Biobuf *b;
        Rune *r;
 
-       b = Bopen("/dev/snarf", OWRITE|OTRUNC);
-       if(b == nil)
+       if((r = selrunes()) == nil)
                return;
-       r = selrunes();
-       if(!r)
+       if((b = Bopen("/dev/snarf", OWRITE|OTRUNC)) == nil){
+               free(r);
                return;
+       }
        Bprint(b, "%S", r);
        Bterm(b);
        free(r);
-
 }
 
 void
 plumbsel(void)
 {
-       char buf[1024], wdir[512];
+       char *s, wdir[1024];
        Rune *r;
        int plumb;
 
-       print("plumb\n");
-       if(getwd(wdir, sizeof wdir) == 0)
-               return;
        if((r = selrunes()) == nil)
                return;
-       print("wdir: %s, runes: %S\n", wdir, r);
-       if((plumb = plumbopen("send", OWRITE)) != -1){
-               snprint(buf, sizeof buf, "%S", r);
-               print("buf: '%s'\n", buf);
-               plumbsendtext(plumb, "vt", nil, wdir, buf);
+       if((s = smprint("%S", r)) == nil){
+               free(r);
+               return;
        }
-       close(plumb);
        free(r);
+       if(getwd(wdir, sizeof wdir) == nil){
+               free(s);
+               return;
+       }
+       if((plumb = plumbopen("send", OWRITE)) < 0){
+               free(s);
+               return;
+       }
+       plumbsendtext(plumb, "vt", nil, wdir, s);
+       close(plumb);
+       free(s);
 }
 
 void