Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible Memory Leak #52

Open
SlothNinja opened this issue Aug 14, 2015 · 0 comments
Open

Possible Memory Leak #52

SlothNinja opened this issue Aug 14, 2015 · 0 comments

Comments

@SlothNinja
Copy link

Unless I'm missing something, the addYield method leaks memory.

func (r *renderer) addYield(name string, binding interface{}) {
    funcs := template.FuncMap{
        "yield": func() (template.HTML, error) {
            buf, err := r.execute(name, binding)
            // return safe html here since we are rendering our own template
            return template.HTML(buf.String()), err
        },
        "current": func() (string, error) {
            return name, nil
        },
    }
    r.t.Funcs(funcs)
}

r.execute method Gets a buffer from the buffer pool, but the buffer is never Put back to the pool. I suggest getting rid of the r.execute method (it's two lines of code) and essentially in-lining its functionality. Doing so will allow deferring the buffer Put immediately after the the buffer Get. Seeing these paired together makes it much easier to ensure the buffer is returned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant