Browse Source

Make sure luax_getfile always returns a retained value

Before it would return a retained value if it returned a freshly constructed file, and an unretained value otherwise.
Also update all (3) call sites, to correctly retain or release as needed.
Bart van Strien 6 years ago
parent
commit
cb625d890a
2 changed files with 4 additions and 2 deletions
  1. 3 2
      src/modules/filesystem/wrap_Filesystem.cpp
  2. 1 0
      src/modules/video/wrap_Video.cpp

+ 3 - 2
src/modules/filesystem/wrap_Filesystem.cpp

@@ -214,7 +214,10 @@ File *luax_getfile(lua_State *L, int idx)
 		file = instance()->newFile(filename);
 	}
 	else
+	{
 		file = luax_checkfile(L, idx);
+		file->retain();
+	}
 
 	return file;
 }
@@ -227,7 +230,6 @@ FileData *luax_getfiledata(lua_State *L, int idx)
 	if (lua_isstring(L, idx) || luax_istype(L, idx, File::type))
 	{
 		file = luax_getfile(L, idx);
-		file->retain();
 	}
 	else if (luax_istype(L, idx, FileData::type))
 	{
@@ -260,7 +262,6 @@ Data *luax_getdata(lua_State *L, int idx)
 	if (lua_isstring(L, idx) || luax_istype(L, idx, File::type))
 	{
 		file = luax_getfile(L, idx);
-		file->retain();
 	}
 	else if (luax_istype(L, idx, Data::type))
 	{

+ 1 - 0
src/modules/video/wrap_Video.cpp

@@ -47,6 +47,7 @@ int w_newVideoStream(lua_State *L)
 
 	luax_pushtype(L, stream);
 	stream->release();
+	file->release();
 	return 1;
 }