Mercurial > vim
comparison src/if_lua.c @ 4293:af3a3680fc75 v7.3.896
updated for version 7.3.896
Problem: Memory leaks in Lua interface.
Solution: Fix the leaks, add tests. (Yukihiro Nakadaira)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Mon, 15 Apr 2013 13:49:21 +0200 |
parents | c5eab656ec51 |
children | b4ce0e1fb5a6 |
comparison
equal
deleted
inserted
replaced
4292:3f3eb3268a04 | 4293:af3a3680fc75 |
---|---|
707 } | 707 } |
708 else if (lua_isstring(L, 2)) /* method? */ | 708 else if (lua_isstring(L, 2)) /* method? */ |
709 { | 709 { |
710 const char *s = lua_tostring(L, 2); | 710 const char *s = lua_tostring(L, 2); |
711 if (strncmp(s, "add", 3) == 0 | 711 if (strncmp(s, "add", 3) == 0 |
712 || strncmp(s, "insert", 6) == 0 | 712 || strncmp(s, "insert", 6) == 0) |
713 || strncmp(s, "extend", 6) == 0) | |
714 { | 713 { |
715 lua_getmetatable(L, 1); | 714 lua_getmetatable(L, 1); |
716 lua_getfield(L, -1, s); | 715 lua_getfield(L, -1, s); |
717 } | 716 } |
718 else | 717 else |
743 { | 742 { |
744 typval_T v; | 743 typval_T v; |
745 luaV_totypval(L, 3, &v); | 744 luaV_totypval(L, 3, &v); |
746 clear_tv(&li->li_tv); | 745 clear_tv(&li->li_tv); |
747 copy_tv(&v, &li->li_tv); | 746 copy_tv(&v, &li->li_tv); |
747 clear_tv(&v); | |
748 } | 748 } |
749 return 0; | 749 return 0; |
750 } | 750 } |
751 | 751 |
752 static int | 752 static int |
753 luaV_list_add (lua_State *L) | 753 luaV_list_add (lua_State *L) |
754 { | 754 { |
755 luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST); | 755 luaV_List *lis = luaV_checkudata(L, 1, LUAVIM_LIST); |
756 list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis); | 756 list_T *l = (list_T *) luaV_checkcache(L, (void *) *lis); |
757 listitem_T *li; | 757 typval_T v; |
758 if (l->lv_lock) | 758 if (l->lv_lock) |
759 luaL_error(L, "list is locked"); | 759 luaL_error(L, "list is locked"); |
760 li = listitem_alloc(); | 760 lua_settop(L, 2); |
761 if (li != NULL) | 761 luaV_totypval(L, 2, &v); |
762 { | 762 if (list_append_tv(l, &v) == FAIL) |
763 typval_T v; | 763 { |
764 lua_settop(L, 2); | 764 clear_tv(&v); |
765 luaV_totypval(L, 2, &v); | 765 luaL_error(L, "Failed to add item to list"); |
766 list_append_tv(l, &v); | 766 } |
767 } | 767 clear_tv(&v); |
768 lua_settop(L, 1); | 768 lua_settop(L, 1); |
769 return 1; | 769 return 1; |
770 } | 770 } |
771 | 771 |
772 static int | 772 static int |
785 if (li == NULL) | 785 if (li == NULL) |
786 luaL_error(L, "invalid position"); | 786 luaL_error(L, "invalid position"); |
787 } | 787 } |
788 lua_settop(L, 2); | 788 lua_settop(L, 2); |
789 luaV_totypval(L, 2, &v); | 789 luaV_totypval(L, 2, &v); |
790 list_insert_tv(l, &v, li); | 790 if (list_insert_tv(l, &v, li) == FAIL) |
791 { | |
792 clear_tv(&v); | |
793 luaL_error(L, "Failed to add item to list"); | |
794 } | |
795 clear_tv(&v); | |
791 lua_settop(L, 1); | 796 lua_settop(L, 1); |
792 return 1; | 797 return 1; |
793 } | 798 } |
794 | 799 |
795 static const luaL_Reg luaV_List_mt[] = { | 800 static const luaL_Reg luaV_List_mt[] = { |
906 } | 911 } |
907 else { | 912 else { |
908 typval_T v; | 913 typval_T v; |
909 luaV_totypval(L, 3, &v); | 914 luaV_totypval(L, 3, &v); |
910 copy_tv(&v, &di->di_tv); | 915 copy_tv(&v, &di->di_tv); |
916 clear_tv(&v); | |
911 } | 917 } |
912 return 0; | 918 return 0; |
913 } | 919 } |
914 | 920 |
915 static const luaL_Reg luaV_Dict_mt[] = { | 921 static const luaL_Reg luaV_Dict_mt[] = { |
1321 luaV_eval(lua_State *L) | 1327 luaV_eval(lua_State *L) |
1322 { | 1328 { |
1323 typval_T *tv = eval_expr((char_u *) luaL_checkstring(L, 1), NULL); | 1329 typval_T *tv = eval_expr((char_u *) luaL_checkstring(L, 1), NULL); |
1324 if (tv == NULL) luaL_error(L, "invalid expression"); | 1330 if (tv == NULL) luaL_error(L, "invalid expression"); |
1325 luaV_pushtypval(L, tv); | 1331 luaV_pushtypval(L, tv); |
1332 free_tv(tv); | |
1326 return 1; | 1333 return 1; |
1327 } | 1334 } |
1328 | 1335 |
1329 static int | 1336 static int |
1330 luaV_beep(lua_State *L UNUSED) | 1337 luaV_beep(lua_State *L UNUSED) |