From 04dd8b95347050d6a99d3eb52ef8aec6ff24b592 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sun, 25 Sep 2016 22:02:08 +0100 Subject: [PATCH] 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 | 2 -- internal/courier/procmail.go | 3 ++- internal/queue/queue.go | 3 ++- 3 files changed, 4 insertions(+), 4 deletions(-) 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