Hi Sean,
On 21 November 2014 19:26, Sean McCully <
seanm...@gmail.com> wrote:
> So I had previously rewritten the strings_to_strarray function as follows,
It's still not correct. The following line:
arr.strings = ffi.new("char *[]", strings)
is always bogus, by itself, if "arr" is a cdata struct. Let me try
again to explain why: this line allocates a "char *[]" whose lifetime
is based on the cdata object that it returns; then "arr.strings = "
will take this new cdata object, get the pointer stored in it, and
copy this pointer into the memory area owned by "arr". Once it is
done, the intermediate cdata object is not needed any more, so it is
deallocated. This causes the "char *[]" array to be deallocated as
well. As a result, after running this line, you have in "arr" a cdata
struct, and in this struct, there is a bogus pointer to freed memory.
A bientôt,
Armin.