1
0
mirror of https://blitiri.com.ar/repos/chasquid synced 2025-12-17 14:37:02 +00:00

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.
This commit is contained in:
Alberto Bertogli
2016-09-25 22:02:08 +01:00
parent 0995eac474
commit 04dd8b9534
3 changed files with 4 additions and 4 deletions

View File

@@ -372,8 +372,6 @@ func (s *Server) serve(l net.Listener, mode SocketMode) {
} }
go sc.Handle() go sc.Handle()
} }
l.Close()
} }
type Conn struct { type Conn struct {

View File

@@ -51,8 +51,9 @@ func (p *Procmail) Deliver(from string, to string, data []byte) (error, bool) {
args = append(args, replacer.Replace(a)) args = append(args, replacer.Replace(a))
} }
ctx, _ := context.WithDeadline(context.Background(), ctx, cancel := context.WithDeadline(context.Background(),
time.Now().Add(p.Timeout)) time.Now().Add(p.Timeout))
defer cancel()
cmd := exec.CommandContext(ctx, p.Binary, args...) cmd := exec.CommandContext(ctx, p.Binary, args...)
cmdStdin, err := cmd.StdinPipe() cmdStdin, err := cmd.StdinPipe()

View File

@@ -386,8 +386,9 @@ func (item *Item) deliver(q *Queue, rcpt *Recipient) (err error, permanent bool)
if len(c) == 0 { if len(c) == 0 {
return fmt.Errorf("empty pipe"), true return fmt.Errorf("empty pipe"), true
} }
ctx, _ := context.WithDeadline(context.Background(), ctx, cancel := context.WithDeadline(context.Background(),
time.Now().Add(30*time.Second)) time.Now().Add(30*time.Second))
defer cancel()
cmd := exec.CommandContext(ctx, c[0], c[1:]...) cmd := exec.CommandContext(ctx, c[0], c[1:]...)
cmd.Stdin = bytes.NewReader(item.Data) cmd.Stdin = bytes.NewReader(item.Data)
return cmd.Run(), true return cmd.Run(), true