mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 22:00:49 +01:00
Merge pull request #122 from wneessen/121-using-defer-inside-for-loop-could-lead-to-leaks
Remove defer from for loops
This commit is contained in:
commit
89fd5dfa06
1 changed files with 23 additions and 12 deletions
|
@ -808,13 +808,7 @@ func TestHello(t *testing.T) {
|
||||||
t.Fatalf("Hello server and client size mismatch")
|
t.Fatalf("Hello server and client size mismatch")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < len(helloServer); i++ {
|
tf := func(fake faker, i int) error {
|
||||||
server := strings.Join(strings.Split(baseHelloServer+helloServer[i], "\n"), "\r\n")
|
|
||||||
client := strings.Join(strings.Split(baseHelloClient+helloClient[i], "\n"), "\r\n")
|
|
||||||
var cmdbuf strings.Builder
|
|
||||||
bcmdbuf := bufio.NewWriter(&cmdbuf)
|
|
||||||
var fake faker
|
|
||||||
fake.ReadWriter = bufio.NewReadWriter(bufio.NewReader(strings.NewReader(server)), bcmdbuf)
|
|
||||||
c, err := NewClient(fake, "fake.host")
|
c, err := NewClient(fake, "fake.host")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("NewClient: %v", err)
|
t.Fatalf("NewClient: %v", err)
|
||||||
|
@ -871,6 +865,20 @@ func TestHello(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Command %d failed: %v", i, err)
|
t.Errorf("Command %d failed: %v", i, err)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 0; i < len(helloServer); i++ {
|
||||||
|
server := strings.Join(strings.Split(baseHelloServer+helloServer[i], "\n"), "\r\n")
|
||||||
|
client := strings.Join(strings.Split(baseHelloClient+helloClient[i], "\n"), "\r\n")
|
||||||
|
var cmdbuf strings.Builder
|
||||||
|
bcmdbuf := bufio.NewWriter(&cmdbuf)
|
||||||
|
var fake faker
|
||||||
|
fake.ReadWriter = bufio.NewReadWriter(bufio.NewReader(strings.NewReader(server)), bcmdbuf)
|
||||||
|
|
||||||
|
if err := tf(fake, i); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := bcmdbuf.Flush(); err != nil {
|
if err := bcmdbuf.Flush(); err != nil {
|
||||||
t.Errorf("flush failed: %s", err)
|
t.Errorf("flush failed: %s", err)
|
||||||
|
@ -1241,6 +1249,13 @@ func serverHandle(c net.Conn, t *testing.T) error {
|
||||||
send := smtpSender{c}.send
|
send := smtpSender{c}.send
|
||||||
send("220 127.0.0.1 ESMTP service ready")
|
send("220 127.0.0.1 ESMTP service ready")
|
||||||
s := bufio.NewScanner(c)
|
s := bufio.NewScanner(c)
|
||||||
|
tf := func(config *tls.Config) error {
|
||||||
|
c = tls.Server(c, config)
|
||||||
|
defer func() {
|
||||||
|
_ = c.Close()
|
||||||
|
}()
|
||||||
|
return serverHandleTLS(c, t)
|
||||||
|
}
|
||||||
for s.Scan() {
|
for s.Scan() {
|
||||||
switch s.Text() {
|
switch s.Text() {
|
||||||
case "EHLO localhost":
|
case "EHLO localhost":
|
||||||
|
@ -1254,11 +1269,7 @@ func serverHandle(c net.Conn, t *testing.T) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
config := &tls.Config{Certificates: []tls.Certificate{keypair}}
|
config := &tls.Config{Certificates: []tls.Certificate{keypair}}
|
||||||
c = tls.Server(c, config)
|
return tf(config)
|
||||||
defer func() {
|
|
||||||
_ = c.Close()
|
|
||||||
}()
|
|
||||||
return serverHandleTLS(c, t)
|
|
||||||
default:
|
default:
|
||||||
t.Fatalf("unrecognized command: %q", s.Text())
|
t.Fatalf("unrecognized command: %q", s.Text())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue