Print a warning if an invalid reference is dropped (FS#820)

Previously, if you called luaA_object_decref() it would silently *create* a new
reference with reference count -1. Obviously, this is not good.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-12-11 13:25:44 +01:00
parent 66aa5beaf7
commit 22a5137299
1 changed files with 12 additions and 0 deletions

View File

@ -20,6 +20,7 @@
*/
#include "common/luaobject.h"
#include "common/backtrace.h"
/** Setup the object system at startup.
* \param L The Lua VM state.
@ -113,6 +114,17 @@ luaA_object_decref(lua_State *L, int tud, void *pointer)
lua_rawget(L, -2);
/* Get the number of references and decrement it */
int count = lua_tonumber(L, -1) - 1;
/* Did we find the item in our table? (tonumber(nil)-1) is -1 */
if (count < 0)
{
buffer_t buf;
backtrace_get(&buf);
warn("BUG: Reference not found: %d %p\n%s", tud, pointer, buf.s);
/* Pop reference count and metatable */
lua_pop(L, 2);
return;
}
lua_pop(L, 1);
/* Push the pointer (key) */
lua_pushlightuserdata(L, pointer);