git » chasquid » commit 04dd8b9

Remove unreachable code, and don't leak contexts

author Alberto Bertogli
2016-09-25 21:02:08 UTC
committer Alberto Bertogli
2016-10-09 23:51:04 UTC
parent 0995eac4742354f8e576b28235a27b448356d7a8

Remove unreachable code, and don't leak contexts

This patch performs some minor cleanups for things detected by "go vet":

 - Remove one line of unreachable code.
 - Don't leak contexts until their deadline expires, cancel them.

chasquid.go +0 -2
internal/courier/procmail.go +2 -1
internal/queue/queue.go +2 -1

diff --git a/chasquid.go b/chasquid.go
index 57e7398..0121984 100644
--- a/chasquid.go
+++ b/chasquid.go
@@ -372,8 +372,6 @@ func (s *Server) serve(l net.Listener, mode SocketMode) {
 		}
 		go sc.Handle()
 	}
-
-	l.Close()
 }
 
 type Conn struct {
diff --git a/internal/courier/procmail.go b/internal/courier/procmail.go
index 0f54c8e..c043165 100644
--- a/internal/courier/procmail.go
+++ b/internal/courier/procmail.go
@@ -51,8 +51,9 @@ func (p *Procmail) Deliver(from string, to string, data []byte) (error, bool) {
 		args = append(args, replacer.Replace(a))
 	}
 
-	ctx, _ := context.WithDeadline(context.Background(),
+	ctx, cancel := context.WithDeadline(context.Background(),
 		time.Now().Add(p.Timeout))
+	defer cancel()
 	cmd := exec.CommandContext(ctx, p.Binary, args...)
 
 	cmdStdin, err := cmd.StdinPipe()
diff --git a/internal/queue/queue.go b/internal/queue/queue.go
index 865722e..68d534c 100644
--- a/internal/queue/queue.go
+++ b/internal/queue/queue.go
@@ -386,8 +386,9 @@ func (item *Item) deliver(q *Queue, rcpt *Recipient) (err error, permanent bool)
 		if len(c) == 0 {
 			return fmt.Errorf("empty pipe"), true
 		}
-		ctx, _ := context.WithDeadline(context.Background(),
+		ctx, cancel := context.WithDeadline(context.Background(),
 			time.Now().Add(30*time.Second))
+		defer cancel()
 		cmd := exec.CommandContext(ctx, c[0], c[1:]...)
 		cmd.Stdin = bytes.NewReader(item.Data)
 		return cmd.Run(), true