Last active
November 12, 2018 08:14
-
-
Save nikolaiianchuk/52daf395f1c9d05ac28debbca506fc00 to your computer and use it in GitHub Desktop.
GoCV memory leaking on IMDecode function?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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