added or adjusted missing closes

This commit is contained in:
farhan 2021-01-30 14:30:49 +00:00
parent cd8ecce807
commit 55cb51b94e
3 changed files with 6 additions and 4 deletions

3
ctl.go
View File

@ -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()
}

View File

@ -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 {

View File

@ -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()