Prevent crash in Lua bindings.
authorcommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 17 Dec 2013 14:28:19 +0000 (14:28 +0000)
committercommit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>
Tue, 17 Dec 2013 14:28:19 +0000 (14:28 +0000)
SkPaint::getTypeface() can return NULL; paint:getTypeface() would
attempt to refcount that value before storing it on the Lua stack
and crash. This is a minimal workaround that fixes the crash.

R=reed@google.com, tomhudson@google.com, robertphillips@google.com

Author: tomhudson@chromium.org

Review URL: https://codereview.chromium.org/109793010

git-svn-id: http://skia.googlecode.com/svn/trunk@12706 2bbb7eff-a529-9590-31e7-b0007b416f81

src/utils/SkLua.cpp

index 767e1772299ef1d2ef32ad37663f549d610dacc8..f27e0cc051115976956e7c380157889be23761b6 100644 (file)
@@ -56,7 +56,7 @@ template <typename T> void push_obj(lua_State* L, const T& obj) {
 }
 
 template <typename T> void push_ref(lua_State* L, T* ref) {
-    *(T**)lua_newuserdata(L, sizeof(T*)) = SkRef(ref);
+    *(T**)lua_newuserdata(L, sizeof(T*)) = SkSafeRef(ref);
     luaL_getmetatable(L, get_mtname<T>());
     lua_setmetatable(L, -2);
 }
@@ -974,7 +974,7 @@ static const struct luaL_Reg gSkImage_Methods[] = {
 ///////////////////////////////////////////////////////////////////////////////
 
 static int ltypeface_gc(lua_State* L) {
-    get_ref<SkTypeface>(L, 1)->unref();
+    SkSafeUnref(get_ref<SkTypeface>(L, 1));
     return 0;
 }