diff --git a/ctl.go b/ctl.go index e79dd59..e1e57e6 100644 --- a/ctl.go +++ b/ctl.go @@ -35,7 +35,7 @@ func startctl() { } func handleClient(commandClient net.Conn) { - + defer commandClient.Close() sizebyte := make([]byte, 4) var commandmap CommandMap var responseback ResponseBack @@ -112,5 +112,4 @@ func handleClient(commandClient net.Conn) { if err != nil { logFatal.Fatal("Error on write:", err) } - commandClient.Close() } diff --git a/oauth.go b/oauth.go index a85c5c9..beb85f5 100644 --- a/oauth.go +++ b/oauth.go @@ -40,6 +40,7 @@ func register_client(endpoint string, o *RunningInstance) error { logErr.Print("Unable to connect to "+api_base_apps+" ", err) return err } + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -48,7 +49,6 @@ func register_client(endpoint string, o *RunningInstance) error { o.client_secret = "" return err } - defer resp.Body.Close() bodymap := make(map[string]string) err = json.Unmarshal(body, &bodymap) @@ -149,6 +149,7 @@ func oauth_login(endpoint string, o *RunningInstance, username string, password logErr.Print("Cannot connect to "+endpoint+": ", err) return OAuth{}, err } + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { @@ -188,6 +189,7 @@ func oauth_refresh(endpoint string, client_id string, client_secret string, refr logErr.Print("Unable to connect to "+endpoint+": ", err) return OAuth{}, err } + defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { diff --git a/poll.go b/poll.go index 5ed1b4a..e42926d 100644 --- a/poll.go +++ b/poll.go @@ -148,6 +148,7 @@ func PollMastodonPleroma(endpoint string, o *RunningInstance) { } err = json.NewDecoder(resp.Body).Decode(&newposts) + resp.Body.Close() // Release as soon as done if err != nil { if parsing_error > 5 { m.Status = BAD_RESPONSE @@ -160,7 +161,7 @@ func PollMastodonPleroma(endpoint string, o *RunningInstance) { parsing_error = parsing_error + 1 time.Sleep(time.Second * 30) } - resp.Body.Close() // Release as soon as done +// resp.Body.Close() // Release as soon as done m.Status = RUNNING ri_mutex.Lock()