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