lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


I am creating lua  binding for my library. And it works fine.
But  when I run a test under valgrind memory error detector
some errors pop up. As I was trying to narrow it down where
is error I came to this artificial minimal example that shows
same symptoms

-- mylib.c
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"

#include <math.h>

static int l_sin(lua_State *L)
{
        double d = luaL_checknumber(L, 1);
        lua_pushnumber(L, sin(d));
        return 1;
}

static const luaL_reg mylib_f [] = {
        {"mysin", l_sin},
        {0, 0}
};

LUALIB_API int
luaopen_mylib(lua_State *L)
{
        luaL_register(L, "mylib", mylib_f);
        return 0;
}

I am compiling this file with
gcc -shared -o mylib.so mylib.c -I/usr/include/lua5.1

Then I have small test program

-- test.lua
require('mylib')
local mysin = mylib.mysin
print("mysin(1) =", mysin(1))
print("math.sin(1) =", math.sin(1))

It runs ok like this:
$ lua test.lua
mysin(1) =      0.8414709848079
math.sin(1) =   0.8414709848079

But when I run it under valgrind it shows some errors. There are no
memory leaks but some invalid memory access.
Can somebody confirm that this is not happening only to me?  Should I
be worried about this? And what I need to do to fix it?

Martin

$ valgrind lua test.lua 
==7008== Memcheck, a memory error detector.
==7008== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==7008== Using LibVEX rev 1658, a library for dynamic binary translation.
==7008== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==7008== Using valgrind-3.2.1-Debian, a dynamic binary instrumentation framework.
==7008== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==7008== For more details, rerun with: -v
==7008== 
==7008== Invalid read of size 4
==7008==    at 0x4010CB8: (within /lib/ld-2.3.6.so)
==7008==    by 0x4006704: (within /lib/ld-2.3.6.so)
==7008==    by 0x418C36F: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x418BDDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x4058D8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x405942C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x4058D20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x806529C: (within /usr/bin/lua5.1)
==7008==    by 0x8065402: (within /usr/bin/lua5.1)
==7008==    by 0x804F0FB: (within /usr/bin/lua5.1)
==7008==  Address 0x420C8A0 is 24 bytes inside a block of size 27 alloc'd
==7008==    at 0x401C38B: malloc (vg_replace_malloc.c:149)
==7008==    by 0x401C415: realloc (vg_replace_malloc.c:306)
==7008==    by 0x80510A2: (within /usr/bin/lua5.1)
==7008==    by 0x8054A95: (within /usr/bin/lua5.1)
==7008==    by 0x804C55A: lua_pushlstring (in /usr/bin/lua5.1)
==7008==    by 0x805876B: (within /usr/bin/lua5.1)
==7008==    by 0x8058CA0: luaL_pushresult (in /usr/bin/lua5.1)
==7008==    by 0x80590C2: luaL_gsub (in /usr/bin/lua5.1)
==7008==    by 0x8065010: (within /usr/bin/lua5.1)
==7008==    by 0x80653E8: (within /usr/bin/lua5.1)
==7008==    by 0x804F0FB: (within /usr/bin/lua5.1)
==7008==    by 0x804F53F: (within /usr/bin/lua5.1)
==7008== 
==7008== Invalid read of size 4
==7008==    at 0x4010E00: (within /lib/ld-2.3.6.so)
==7008==    by 0x4006704: (within /lib/ld-2.3.6.so)
==7008==    by 0x418C36F: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x418BDDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x4058D8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x405942C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x4058D20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x806529C: (within /usr/bin/lua5.1)
==7008==    by 0x8065402: (within /usr/bin/lua5.1)
==7008==    by 0x804F0FB: (within /usr/bin/lua5.1)
==7008==  Address 0x420C8A0 is 24 bytes inside a block of size 27 alloc'd
==7008==    at 0x401C38B: malloc (vg_replace_malloc.c:149)
==7008==    by 0x401C415: realloc (vg_replace_malloc.c:306)
==7008==    by 0x80510A2: (within /usr/bin/lua5.1)
==7008==    by 0x8054A95: (within /usr/bin/lua5.1)
==7008==    by 0x804C55A: lua_pushlstring (in /usr/bin/lua5.1)
==7008==    by 0x805876B: (within /usr/bin/lua5.1)
==7008==    by 0x8058CA0: luaL_pushresult (in /usr/bin/lua5.1)
==7008==    by 0x80590C2: luaL_gsub (in /usr/bin/lua5.1)
==7008==    by 0x8065010: (within /usr/bin/lua5.1)
==7008==    by 0x80653E8: (within /usr/bin/lua5.1)
==7008==    by 0x804F0FB: (within /usr/bin/lua5.1)
==7008==    by 0x804F53F: (within /usr/bin/lua5.1)
==7008== 
==7008== Invalid read of size 4
==7008==    at 0x4010E00: (within /lib/ld-2.3.6.so)
==7008==    by 0x4004B78: (within /lib/ld-2.3.6.so)
==7008==    by 0x4006792: (within /lib/ld-2.3.6.so)
==7008==    by 0x418C36F: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x418BDDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x4058D8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x405942C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x4058D20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x806529C: (within /usr/bin/lua5.1)
==7008==    by 0x8065402: (within /usr/bin/lua5.1)
==7008==  Address 0x420C8A0 is 24 bytes inside a block of size 27 alloc'd
==7008==    at 0x401C38B: malloc (vg_replace_malloc.c:149)
==7008==    by 0x401C415: realloc (vg_replace_malloc.c:306)
==7008==    by 0x80510A2: (within /usr/bin/lua5.1)
==7008==    by 0x8054A95: (within /usr/bin/lua5.1)
==7008==    by 0x804C55A: lua_pushlstring (in /usr/bin/lua5.1)
==7008==    by 0x805876B: (within /usr/bin/lua5.1)
==7008==    by 0x8058CA0: luaL_pushresult (in /usr/bin/lua5.1)
==7008==    by 0x80590C2: luaL_gsub (in /usr/bin/lua5.1)
==7008==    by 0x8065010: (within /usr/bin/lua5.1)
==7008==    by 0x80653E8: (within /usr/bin/lua5.1)
==7008==    by 0x804F0FB: (within /usr/bin/lua5.1)
==7008==    by 0x804F53F: (within /usr/bin/lua5.1)
==7008== 
==7008== Conditional jump or move depends on uninitialised value(s)
==7008==    at 0x4010C8D: (within /lib/ld-2.3.6.so)
==7008==    by 0x4004B78: (within /lib/ld-2.3.6.so)
==7008==    by 0x4006792: (within /lib/ld-2.3.6.so)
==7008==    by 0x418C36F: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x418BDDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x4058D8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x405942C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x4058D20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x806529C: (within /usr/bin/lua5.1)
==7008==    by 0x8065402: (within /usr/bin/lua5.1)
==7008== 
==7008== Conditional jump or move depends on uninitialised value(s)
==7008==    at 0x40089F2: (within /lib/ld-2.3.6.so)
==7008==    by 0x418C7C4: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x418BDDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x4058D8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x405942C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x4058D20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x806529C: (within /usr/bin/lua5.1)
==7008==    by 0x8065402: (within /usr/bin/lua5.1)
==7008==    by 0x804F0FB: (within /usr/bin/lua5.1)
==7008==    by 0x804F53F: (within /usr/bin/lua5.1)
==7008== 
==7008== Conditional jump or move depends on uninitialised value(s)
==7008==    at 0x4008E57: (within /lib/ld-2.3.6.so)
==7008==    by 0x418C7C4: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x418BDDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x4058D8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x405942C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x4058D20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x806529C: (within /usr/bin/lua5.1)
==7008==    by 0x8065402: (within /usr/bin/lua5.1)
==7008==    by 0x804F0FB: (within /usr/bin/lua5.1)
==7008==    by 0x804F53F: (within /usr/bin/lua5.1)
==7008== 
==7008== Conditional jump or move depends on uninitialised value(s)
==7008==    at 0x4008C58: (within /lib/ld-2.3.6.so)
==7008==    by 0x418C7C4: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x418BDDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x4058D8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x405942C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x4058D20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x806529C: (within /usr/bin/lua5.1)
==7008==    by 0x8065402: (within /usr/bin/lua5.1)
==7008==    by 0x804F0FB: (within /usr/bin/lua5.1)
==7008==    by 0x804F53F: (within /usr/bin/lua5.1)
==7008== 
==7008== Conditional jump or move depends on uninitialised value(s)
==7008==    at 0x4008ED5: (within /lib/ld-2.3.6.so)
==7008==    by 0x418C7C4: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x418BDDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x4058D8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x405942C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x4058D20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x806529C: (within /usr/bin/lua5.1)
==7008==    by 0x8065402: (within /usr/bin/lua5.1)
==7008==    by 0x804F0FB: (within /usr/bin/lua5.1)
==7008==    by 0x804F53F: (within /usr/bin/lua5.1)
==7008== 
==7008== Conditional jump or move depends on uninitialised value(s)
==7008==    at 0x4008B2E: (within /lib/ld-2.3.6.so)
==7008==    by 0x418C7C4: (within /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x418BDDE: _dl_open (in /lib/tls/i686/cmov/libc-2.3.6.so)
==7008==    by 0x4058D8D: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x400B44E: (within /lib/ld-2.3.6.so)
==7008==    by 0x405942C: (within /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x4058D20: dlopen (in /lib/tls/i686/cmov/libdl-2.3.6.so)
==7008==    by 0x806529C: (within /usr/bin/lua5.1)
==7008==    by 0x8065402: (within /usr/bin/lua5.1)
==7008==    by 0x804F0FB: (within /usr/bin/lua5.1)
==7008==    by 0x804F53F: (within /usr/bin/lua5.1)
mysin(1) =	0.8414709848079
math.sin(1) =	0.8414709848079
==7008== 
==7008== ERROR SUMMARY: 10 errors from 9 contexts (suppressed: 19 from 1)
==7008== malloc/free: in use at exit: 0 bytes in 0 blocks.
==7008== malloc/free: 512 allocs, 512 frees, 32,209 bytes allocated.
==7008== For counts of detected errors, rerun with: -v
==7008== All heap blocks were freed -- no leaks are possible.