mirror of
https://github.com/astaxie/beego.git
synced 2024-11-24 15:30:55 +00:00
fix memory leak of request context
This commit is contained in:
parent
9d936c58bf
commit
cfff0f3b46
@ -323,9 +323,37 @@ func (input *BeegoInput) SetParam(key, val string) {
|
|||||||
// This function is used to clear parameters so they may be reset between filter
|
// This function is used to clear parameters so they may be reset between filter
|
||||||
// passes.
|
// passes.
|
||||||
func (input *BeegoInput) ResetParams() {
|
func (input *BeegoInput) ResetParams() {
|
||||||
|
if len(input.pnames) > 0 {
|
||||||
input.pnames = input.pnames[:0]
|
input.pnames = input.pnames[:0]
|
||||||
|
}
|
||||||
|
if len(input.pvalues) > 0 {
|
||||||
input.pvalues = input.pvalues[:0]
|
input.pvalues = input.pvalues[:0]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetData: reset data
|
||||||
|
func (input *BeegoInput) ResetData() {
|
||||||
|
input.dataLock.Lock()
|
||||||
|
if input.data != nil {
|
||||||
|
input.data = nil
|
||||||
|
}
|
||||||
|
input.dataLock.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ResetBody: reset body
|
||||||
|
func (input *BeegoInput) ResetBody() {
|
||||||
|
if len(input.RequestBody) > 0 {
|
||||||
|
input.RequestBody = []byte{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear: clear all data in input
|
||||||
|
func (input *BeegoInput) Clear() {
|
||||||
|
input.ResetParams()
|
||||||
|
input.ResetData()
|
||||||
|
input.ResetBody()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// Query returns input data item string by a given string.
|
// Query returns input data item string by a given string.
|
||||||
func (input *BeegoInput) Query(key string) string {
|
func (input *BeegoInput) Query(key string) string {
|
||||||
|
@ -50,9 +50,15 @@ func NewOutput() *BeegoOutput {
|
|||||||
// Reset init BeegoOutput
|
// Reset init BeegoOutput
|
||||||
func (output *BeegoOutput) Reset(ctx *Context) {
|
func (output *BeegoOutput) Reset(ctx *Context) {
|
||||||
output.Context = ctx
|
output.Context = ctx
|
||||||
|
output.Clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clear: clear all data in output
|
||||||
|
func (output *BeegoOutput) Clear() {
|
||||||
output.Status = 0
|
output.Status = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Header sets response header item string via given key.
|
// Header sets response header item string via given key.
|
||||||
func (output *BeegoOutput) Header(key, val string) {
|
func (output *BeegoOutput) Header(key, val string) {
|
||||||
output.Context.ResponseWriter.Header().Set(key, val)
|
output.Context.ResponseWriter.Header().Set(key, val)
|
||||||
|
@ -319,6 +319,10 @@ func (p *ControllerRegister) GetContext() *beecontext.Context {
|
|||||||
|
|
||||||
// GiveBackContext put the ctx into pool so that it could be reuse
|
// GiveBackContext put the ctx into pool so that it could be reuse
|
||||||
func (p *ControllerRegister) GiveBackContext(ctx *beecontext.Context) {
|
func (p *ControllerRegister) GiveBackContext(ctx *beecontext.Context) {
|
||||||
|
// clear input cached data
|
||||||
|
ctx.Input.Clear()
|
||||||
|
// clear output cached data
|
||||||
|
ctx.Output.Clear()
|
||||||
p.pool.Put(ctx)
|
p.pool.Put(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user