Patch 9.0.1093
Problem: Using freed memory of object member. (Yegappan Lakshmanan)
Solution: Make a copy of the object member when getting it.
Files: src/vim9execute.c, src/testdir/test_vim9_class.vim
*** ../vim-9.0.1092/src/vim9execute.c 2022-12-18 21:42:49.014716925 +0000
--- src/vim9execute.c 2022-12-24 15:10:50.767233287 +0000
***************
*** 3799,3805 ****
tv->vval.v_number = iptr->isn_arg.storenr.stnr_val;
break;
! // store value in list or dict variable
case ISN_STOREINDEX:
{
int res = execute_storeindex(iptr, ectx);
--- 3799,3805 ----
tv->vval.v_number = iptr->isn_arg.storenr.stnr_val;
break;
! // Store a value in a list, dict, blob or object variable.
case ISN_STOREINDEX:
{
int res = execute_storeindex(iptr, ectx);
***************
*** 5159,5165 ****
object_T *obj = tv->vval.v_object;
// the members are located right after the object struct
typval_T *mtv = ((typval_T *)(obj + 1)) + idx;
! *tv = *mtv;
// Unreference the object after getting the member, it may
// be freed.
--- 5159,5165 ----
object_T *obj = tv->vval.v_object;
// the members are located right after the object struct
typval_T *mtv = ((typval_T *)(obj + 1)) + idx;
! copy_tv(mtv, tv);
// Unreference the object after getting the member, it may
// be freed.
*** ../vim-9.0.1092/src/testdir/test_vim9_class.vim 2022-12-23
17:56:21.405511534 +0000
--- src/testdir/test_vim9_class.vim 2022-12-24 21:20:39.623390908 +0000
***************
*** 323,328 ****
--- 323,354 ----
assert_fails('trip.four = 4', 'E1334')
END
v9.CheckScriptSuccess(lines)
+
+ lines =<< trim END
+ vim9script
+
+ class MyCar
+ this.make: string
+
+ def new(make_arg: string)
+ this.make = make_arg
+ enddef
+
+ def GetMake(): string
+ return $"make = {this.make}"
+ enddef
+ endclass
+
+ var c = MyCar.new("abc")
+ assert_equal('make = abc', c.GetMake())
+
+ c = MyCar.new("def")
+ assert_equal('make = def', c.GetMake())
+
+ var c2 = MyCar.new("123")
+ assert_equal('make = 123', c2.GetMake())
+ END
+ v9.CheckScriptSuccess(lines)
enddef
def Test_class_member_access()
*** ../vim-9.0.1092/src/version.c 2022-12-23 19:05:54.662600613 +0000
--- src/version.c 2022-12-24 15:11:54.395145229 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 1093,
/**/
--
If your life is a hard drive,
Christ can be your backup.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20221224212515.2CD031C0BAE%40moolenaar.net.