jung-kurt / luahpdf

LuaHPDF is a module that lets you programmatically create PDF files using Lua.
23 stars 10 forks source link

malloc issue on OS X #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
2. start the Lua interpreter
2. load built hpdf.so
3. quit the Lua interpreter (ctrl-D)

What is the expected output? What do you see instead?
Nothing. An error about freeing a non allocated pointer.

What version of the product are you using? On what operating system?
1.0 on OS X 10.6.5

Please provide any additional information below.

Here's full output:
$ lua
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print(package.cpath)
./?.so;/opt/local/lib/lua/5.1/?.so;/opt/local/lib/lua/5.1/loadall.so
> require'hpdf'
> print(hpdf.VERSION_TEXT)
2.2.0
> 
lua(86919) malloc: *** error for object 0x100232520: pointer being freed was 
not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap
$ 

Original issue reported on code.google.com by and.dam...@gmail.com on 17 Nov 2010 at 9:51

GoogleCodeExporter commented 9 years ago
I do not have this problem on Linux (Fedora, Ubuntu) or Windows XP. 
Unfortunately, I don't have a convenient Mac to test this.

One difference I see is the version of the HPDF library. Can you try using the 
latest library from https://github.com/tony2001/libharu.git ?

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> print(package.cpath)
./?.so;/usr/lib/lua/5.1/?.so
> require 'hpdf'
> print(hpdf.VERSION_TEXT)
2.3.0-dev
>

-- Kurt

Original comment by kurt.w.jung on 17 Nov 2010 at 11:45

GoogleCodeExporter commented 9 years ago
I'll try, in the meanwihle I'm attaching the backtrace:

$ gdb lua
GNU gdb 6.3.50-20050815 (Apple version gdb-1472) (Wed Jul 21 10:53:12 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin"...Reading symbols for shared 
libraries ... done

(gdb) b malloc_error_break
Breakpoint 1 at 0x20c49ba5d4f76d
(gdb) r
Starting program: /opt/local/bin/lua 
Reading symbols for shared libraries ++.. done
Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require "hpdf"
Reading symbols for shared libraries .... done
> print(hpdf.VERSION_TEXT)
2.2.0
> 
lua(92782) malloc: *** error for object 0x100232520: pointer being freed was 
not allocated
*** set a breakpoint in malloc_error_break to debug

Breakpoint 1, 0x00007fff8737c76d in malloc_error_break ()
(gdb) bt
#0  0x00007fff8737c76d in malloc_error_break ()
#1  0x00007fff872a66e3 in free ()
#2  0x000000010001306a in l_alloc ()
#3  0x000000010000b320 in luaM_realloc_ ()
#4  0x000000010000f17a in luaH_free ()
#5  0x0000000100009535 in sweeplist ()
#6  0x00000001000095b7 in luaC_freeall ()
#7  0x000000010000e86f in close_state ()
#8  0x0000000100001624 in main ()
(gdb) 

Original comment by and.dam...@gmail.com on 18 Nov 2010 at 6:45

GoogleCodeExporter commented 9 years ago
Based on this message, I think that hpdf.so is using a separate Lua instance:

  http://lua-users.org/lists/lua-l/2009-10/msg00145.html

Check where Lua is being pulled in for both hpdf.so and lua:

$ ldd ./hpdf.so
        linux-gate.so.1 =>  (0x00423000)
        liblua-5.1.so => /usr/lib/liblua-5.1.so (0x0057d000)
        libhpdf-2.3.0-dev.so => /usr/lib/libhpdf-2.3.0-dev.so (0x00d6e000)
        libc.so.6 => /lib/libc.so.6 (0x00110000)
        libm.so.6 => /lib/libm.so.6 (0x00782000)
        libdl.so.2 => /lib/libdl.so.2 (0x00606000)
        libz.so.1 => /lib/libz.so.1 (0x00426000)
        libpng12.so.0 => /usr/lib/libpng12.so.0 (0x00ea0000)
        /lib/ld-linux.so.2 (0x00ab7000)
$ ldd `which lua`
        linux-gate.so.1 =>  (0x00c81000)
        liblua-5.1.so => /usr/lib/liblua-5.1.so (0x002f3000)
        libreadline.so.6 => /lib/libreadline.so.6 (0x00cf8000)
        libncurses.so.5 => /lib/libncurses.so.5 (0x04ef6000)
        libm.so.6 => /lib/libm.so.6 (0x00c8b000)
        libdl.so.2 => /lib/libdl.so.2 (0x00c84000)
        libc.so.6 => /lib/libc.so.6 (0x00ad9000)
        libtinfo.so.5 => /lib/libtinfo.so.5 (0x04ed3000)
        /lib/ld-linux.so.2 (0x00ab7000)

Original comment by kurt.w.jung on 18 Nov 2010 at 11:49

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I get:

$ otool -L `which lua` hpdf.so
/opt/local/bin/lua:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.0.1)
    /opt/local/lib/libreadline.6.1.dylib (compatibility version 6.0.0, current version 6.1.0)
hpdf.so:
    hpdf.so (compatibility version 0.0.0, current version 0.0.0)
    /opt/local/lib/libhpdf-2.2.0.dylib (compatibility version 0.0.0, current version 0.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
bimac:luahpdf-1.0 $ 

I have only one version of Lua on my system, tho' I see I just get a liblua.a 
archive rather than a dylib Mach-O, I'll try to rebuild it later and report 
results.

Original comment by and.dam...@gmail.com on 18 Nov 2010 at 1:06

GoogleCodeExporter commented 9 years ago
Trouble: it looks like lua is statically linked in hpdf.so. 

Original comment by kurt.w.jung on 18 Nov 2010 at 1:26

GoogleCodeExporter commented 9 years ago

Original comment by kurt.w.jung on 18 Nov 2010 at 1:46

GoogleCodeExporter commented 9 years ago
Fixed, it wasn't due to luahpdf.

 cf. http://trac.macports.org/ticket/27378

Original comment by and.dam...@gmail.com on 19 Nov 2010 at 7:22

GoogleCodeExporter commented 9 years ago
Thanks, Andrea

Original comment by kurt.w.jung on 19 Nov 2010 at 10:54