What am I doing wrong?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

What am I doing wrong?

Martin Krpan
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.
Reply | Threaded
Open this post in threaded view
|

Re: What am I doing wrong?

Gabríel "A." Pétursson
On Sat, 2009-08-01 at 22:56 +0200, Martin wrote:
> 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

You may wish to compile Lua with debugging symbols (-ggdb3) for valgrind
to produce more explaining error messages.

Reply | Threaded
Open this post in threaded view
|

Re: What am I doing wrong?

eugeny gladkih
In reply to this post by Martin Krpan
>>>>> "Martin" == Martin  <[hidden email]> writes:

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

nothing, that's not your problem. you have too old valgrind and/or
shown errors are in glibc. you may just ignore 'em

 Martin> ==7008== Using valgrind-3.2.1-Debian, a dynamic binary instrumentation framework.

--
Yours sincerely, Eugeny.
GM of Enterprise Solutions Department
Doctor Web, Ltd.
http://www.drweb.com, +79119997425
Reply | Threaded
Open this post in threaded view
|

Re: Valgrind (was: What am I doing wrong?)

Irayo


On Aug 2, 2009, at 4:00 AM, eugeny gladkih <[hidden email]> wrote:

>>>>>> "Martin" == Martin  <[hidden email]> writes:
>
> Martin> But when I run it under valgrind it shows some errors. There  
> are no
> Martin> memory leaks but some invalid memory access.
> Martin> Can somebody confirm that this is not happening only to me?  
> Should I
> Martin> be worried about this? And what I need to do to fix it?
>
> nothing, that's not your problem. you have too old valgrind and/or
> shown errors are in glibc. you may just ignore 'em
>
> Martin> ==7008== Using valgrind-3.2.1-Debian, a dynamic binary  
> instrumentation framework.
>

This may be mildly off-topic but certainly Valgrind related. I've been  
debugging my own lib with valgrind and it's very difficult to sift  
through all of the warnings and errors from the libraries I'm using  
(OpenGL in particular seems to confuse valgrind). These are useless to  
me since I can't do anything about them anyway. Is there a switch to  
make it only show results from my test program and library?