Ich versuche, ein C-Programm mit Lua zu schreiben eingebettet innen .. Und habe ich versucht, ein sehr einfaches Programm zu starten, es schafft nur den Lua-Kontext und dann zerstört sie:Lua C API Speicherverlust? (Valgrind)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
}
int main(int argc, char *argv[]) {
lua_State *L = lua_open();
luaL_openlibs(L);
lua_close(L);
fprintf(stderr, "%s: %d\n", __FILE__, __LINE__);
return(0);
}
ich bin kompilieren es etwa so: (ich bin Torch7 tatsächlich verwendet wird, so ..)
g++ -c -g3 -O2 -Wall -Werror -I/usr/local/torch/install/include/ -fPIC pure_lua_test.C -o pure_lua_test.o
g++ -g3 -O2 -Wall -Werror -I/usr/local/torch/install/include/ -fPIC -o pure_lua_test pure_lua_test.o -L/usr/local/torch/install/lib/ -lluajit
Wenn ich es laufen auf seine eigene, druckt es
pure_lua_test.C: 16
wie erwartet (kurz vor die Rückkehr).
Aber, wenn ich es mit valgrind laufen (wie valgrind ./pure_lua_test)
ich
==9165== Memcheck, a memory error detector
==9165== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==9165== Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
==9165== Command: ./pure_lua_test
==9165==
==9165== Invalid read of size 4
==9165== at 0x4E9EE97: lua_pushcclosure (in /usr/local/src/torch-2015-05-25/install/lib/libluajit.so)
==9165== by 0x4EB4CDD: luaL_openlibs (in /usr/local/src/torch-2015-05-25/install/lib/libluajit.so)
==9165== by 0x400700: main (pure_lua_test.C:13)
==9165== Address 0x8 is not stack'd, malloc'd or (recently) free'd
==9165==
==9165==
==9165== Process terminating with default action of signal 11 (SIGSEGV)
==9165== Access not within mapped region at address 0x8
==9165== at 0x4E9EE97: lua_pushcclosure (in /usr/local/src/torch-2015-05-25/install/lib/libluajit.so)
==9165== by 0x4EB4CDD: luaL_openlibs (in /usr/local/src/torch-2015-05-25/install/lib/libluajit.so)
==9165== by 0x400700: main (pure_lua_test.C:13)
==9165== If you believe this happened as a result of a stack
==9165== overflow in your program's main thread (unlikely but
==9165== possible), you can try to increase the size of the
==9165== main thread stack using the --main-stacksize= flag.
==9165== The main thread stack size used in this run was 8388608.
==9165==
==9165== HEAP SUMMARY:
==9165== in use at exit: 0 bytes in 0 blocks
==9165== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==9165==
==9165== All heap blocks were freed -- no leaks are possible
==9165==
==9165== For counts of detected and suppressed errors, rerun with: -v
==9165== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Wer weiß, was passiert ist? Warum SIGSEGV in Valgrind? Ist das etwas, worüber ich mich Sorgen machen sollte? Im Grunde hatte ich gehofft zu überprüfen, dass ein Plugin, das ich für Torch geschrieben habe, keine Speicherlecks hatte ... Aber wenn es damit nicht klappt, bin ich irgendwie festgefahren.
Ich habe versucht, die lua_open() zu luaL_newstate(), aber ich bekomme immer noch das gleiche Problem mit valgrind .. – bnsh
Ist das Ihr Problem behoben? http://stackoverflow.com/questions/14840569/sigsegv-error-in-some-lua-c-code – bleakgadfly
LuaJIT muss mit Valgrind-Unterstützung kompiliert werden. Durchsuchen Sie das LuaJIT-Makefile (im 'src'-Unterverzeichnis) nach' LUAJIT_USE_VALGRIND'. – siffiejoe