trying to fix memory leak...

This commit is contained in:
farhan 2020-11-15 00:12:25 -05:00
parent 4c51cd861a
commit aab707eab0

View File

@ -45,6 +45,7 @@ func StartInstancePoll(instancereport InstanceReport, reportPostChan chan Report
api_timeline := "https://" + instancereport.endpoint + "/api/v1/timelines/public?limit=40&min_id=" + instancereport.min_id
resp, err := http.Get(api_timeline)
if err != nil {
defer resp.Body.Close()
instanceReportChan <- InstanceReport{instancereport.endpoint, CLIENT_ISSUE, "", 0}
return
}
@ -63,38 +64,38 @@ func StartInstancePoll(instancereport InstanceReport, reportPostChan chan Report
min_id := ""
numposts := 0
for _, newpost := range newposts {
if newpost.Account.Acct == "" {
continue
}
sendpost := newpost
posthash := sha1.New()
at_sign := strings.Index(newpost.Account.Acct, "@")
at_sign := strings.Index(sendpost.Account.Acct, "@")
if at_sign == -1 {
at_sign = len(newpost.Account.Acct)
newpost.Account.Acct += "@" + instancereport.endpoint
at_sign = len(sendpost.Account.Acct)
sendpost.Account.Acct += "@" + instancereport.endpoint
}
// Calculate the post hash
fmt.Fprint(posthash, newpost.Url)
fmt.Fprint(posthash, newpost.normalized)
fmt.Fprint(posthash, newpost.Account.Acct)
fmt.Fprint(posthash, newpost.Account.Display_name)
newpost.posthash = posthash.Sum(nil)
fmt.Fprint(posthash, sendpost.Url)
fmt.Fprint(posthash, sendpost.normalized)
fmt.Fprint(posthash, sendpost.Account.Acct)
fmt.Fprint(posthash, sendpost.Account.Display_name)
sendpost.posthash = posthash.Sum(nil)
newpost.normalized = html.UnescapeString(strings.ToLower(p.Sanitize(newpost.Content)))
sendpost.normalized = html.UnescapeString(strings.ToLower(p.Sanitize(sendpost.Content)))
reportPostChan <- newpost
reportPostChan <- sendpost
// Check min_id
if newpost.Id > min_id {
min_id = newpost.Id
if sendpost.Id > min_id {
min_id = sendpost.Id
}
numposts = numposts + 1
newinstance := newpost.Account.Acct[at_sign+1:]
newinstance := sendpost.Account.Acct[at_sign+1:]
newinstances = AppendIfMissing(newinstances, newinstance)
}
@ -116,6 +117,7 @@ func GetNodeInfo(endpoint string, nodeinfo *NodeInfo) {
http_client := http.Client{Timeout: 5 * time.Second}
resp, err := http_client.Get(api_nodeinfo)
if err != nil {
defer resp.Body.Close()
return
}