Mercurial > vim
comparison src/vim9execute.c @ 20283:934657e365e5 v8.2.0697
patch 8.2.0697: Vim9: memory leak when using nested function
Commit: https://github.com/vim/vim/commit/221fcc741a6660bfc3fd0d64937d0c15bb71f51d
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 5 19:46:20 2020 +0200
patch 8.2.0697: Vim9: memory leak when using nested function
Problem: Vim9: memory leak when using nested function.
Solution: Unreference function when deleting instructions. Adjust reference
count for local variables.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 05 May 2020 20:00:04 +0200 |
parents | ab8c8fd0f868 |
children | ce1b73835822 |
comparison
equal
deleted
inserted
replaced
20282:a461511dc68f | 20283:934657e365e5 |
---|---|
262 // Check if any created closure is still in use. | 262 // Check if any created closure is still in use. |
263 for (idx = 0; idx < dfunc->df_closure_count; ++idx) | 263 for (idx = 0; idx < dfunc->df_closure_count; ++idx) |
264 { | 264 { |
265 tv = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_SIZE | 265 tv = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_SIZE |
266 + dfunc->df_varcount + idx); | 266 + dfunc->df_varcount + idx); |
267 if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial->pt_refcount > 1) | 267 if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial != NULL |
268 && tv->vval.v_partial->pt_refcount > 1) | |
268 { | 269 { |
269 closure_in_use = TRUE; | 270 int refcount = tv->vval.v_partial->pt_refcount; |
270 break; | 271 int i; |
272 | |
273 // A Reference in a local variables doesn't count, its get | |
274 // unreferenced on return. | |
275 for (i = 0; i < dfunc->df_varcount; ++i) | |
276 { | |
277 typval_T *stv = STACK_TV(ectx->ec_frame_idx | |
278 + STACK_FRAME_SIZE + i); | |
279 if (stv->v_type == VAR_PARTIAL | |
280 && tv->vval.v_partial == stv->vval.v_partial) | |
281 --refcount; | |
282 } | |
283 if (refcount > 1) | |
284 { | |
285 closure_in_use = TRUE; | |
286 break; | |
287 } | |
271 } | 288 } |
272 } | 289 } |
273 | 290 |
274 if (closure_in_use) | 291 if (closure_in_use) |
275 { | 292 { |