defer release resouce
This commit is contained in:
parent
389bbad65f
commit
ed796e6d7f
|
@ -65,6 +65,7 @@ func fetch(u string) (r rss2.Item) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
dom, err := goquery.NewDocumentFromReader(res.Body)
|
dom, err := goquery.NewDocumentFromReader(res.Body)
|
||||||
|
defer res.Body.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -104,6 +105,7 @@ func downAndSendMail(doc *goquery.Document, title string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
var fn []func()
|
||||||
for _, ss := range []string{".bbcle-download-extension-pdf", ".bbcle-download-extension-mp3"} {
|
for _, ss := range []string{".bbcle-download-extension-pdf", ".bbcle-download-extension-mp3"} {
|
||||||
uu, ok := doc.Find(ss).Attr("href")
|
uu, ok := doc.Find(ss).Attr("href")
|
||||||
if ok {
|
if ok {
|
||||||
|
@ -116,6 +118,10 @@ func downAndSendMail(doc *goquery.Document, title string) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
fn = append(fn, func() {
|
||||||
|
response.Body.Close()
|
||||||
|
file.Close()
|
||||||
|
})
|
||||||
_, err = io.Copy(file, response.Body)
|
_, err = io.Copy(file, response.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
@ -123,6 +129,11 @@ func downAndSendMail(doc *goquery.Document, title string) {
|
||||||
mm.f = append(mm.f, name)
|
mm.f = append(mm.f, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
for _, f := range fn {
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
}()
|
||||||
if len(mm.f) < 1 {
|
if len(mm.f) < 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user