Skip to content

Possible Memory Leak #52

@SlothNinja

Description

@SlothNinja

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions