Skip to content

Instantly share code, notes, and snippets.

@nikolaiianchuk
Last active November 12, 2018 08:14
Show Gist options
  • Save nikolaiianchuk/52daf395f1c9d05ac28debbca506fc00 to your computer and use it in GitHub Desktop.
Save nikolaiianchuk/52daf395f1c9d05ac28debbca506fc00 to your computer and use it in GitHub Desktop.
GoCV memory leaking on IMDecode function?
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"time"
"gocv.io/x/gocv"
)
func main() {
http.HandleFunc("/file", FileHandler)
http.ListenAndServe(":8080", nil)
}
func FileHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println(time.Now(), "FileHander")
r.ParseMultipartForm(2 << 20)
_, h, err := r.FormFile("file")
if err != nil {
fmt.Fprintln(w, err)
}
f, err := h.Open()
bytes, err := ioutil.ReadAll(f)
if err != nil {
fmt.Fprintln(w, err)
}
f.Close()
DecodeAndClose(bytes)
}
func DecodeAndClose(b []byte) {
m, err := gocv.IMDecode(b, gocv.IMReadUnchanged)
if err != nil {
log.Fatal(err)
}
m.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment