Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Inline::C & Strawberry: can't free a buffer allocated with asprintf

by syphilis (Archbishop)
on Jan 02, 2020 at 03:51 UTC ( [id://11110856]=note: print w/replies, xml ) Need Help??


in reply to Inline::C & Strawberry: can't free a buffer allocated with asprintf

For an alternative solution, you can create your own library that provides the free() implementation:
C:\pscrpt> type free.c #include <malloc.h> void C_free(void * ptr) { free(ptr); } C:\pscrpt> gcc -c free.c C:\pscrpt> ar rcs libC_free.a -o free.o C:\pscrpt> type try2.pl use strict; use warnings; BEGIN{ use Cwd; $m::cwd = getcwd() } use Inline C => Config => LIBS => "-L$m::cwd -lC_free"; use Inline C => <<'END_OF_C'; #define _GNU_SOURCE void foo() { char *s; asprintf(&s, "%s", "foo"); C_free(s); } END_OF_C foo(); __END__ C:\pscrpt> perl try2.pl C:\pscrpt>
The success of that script (try2.pl) relies on it being in the same directory as libC_free.a.
Otherwise, modify the LIBS arg in the Inline Config section as necessary.

Cheers,
Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11110856]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-03-28 10:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found