]> Sergey Matveev's repositories - btrtrc.git/commitdiff
cmd/torrentfs: Check error creating client
authorMatt Joiner <anacrolix@gmail.com>
Wed, 1 Apr 2015 03:30:22 +0000 (14:30 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 1 Apr 2015 03:30:22 +0000 (14:30 +1100)
This wouldn't have happened with exceptions ;)

client.go
cmd/torrentfs/main.go

index ed037c6cfcf0c803b2a4f95365faefdde5eed85c..981d4d224b584e611f260a49066938d22d320d36 100644 (file)
--- a/client.go
+++ b/client.go
@@ -491,6 +491,11 @@ func NewClient(cfg *Config) (cl *Client, err error) {
                cfg = &Config{}
        }
 
+       defer func() {
+               if err != nil {
+                       cl = nil
+               }
+       }()
        cl = &Client{
                noUpload:        cfg.NoUpload,
                disableTrackers: cfg.DisableTrackers,
index a7e786ae3fa2a7327f5ec55dba66466381cb8afd..03edc8570c5ba20b5dca49746de39ad534c04282 100644 (file)
@@ -103,6 +103,9 @@ func main() {
                ListenAddr: *listenAddr,
                NoUpload:   true, // Ensure that uploads are responsive.
        })
+       if err != nil {
+               log.Fatal(err)
+       }
        http.DefaultServeMux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
                client.WriteStatus(w)
        })