Re: G::O::I based bindings and problem passing char array ref



On 03.06.2016 21:44, Jeremy Volkening wrote:
Attached is the valgrind dump from my test script. This is after
changing the section of the .gir for poppler_document_new_from_data()

FROM:

<parameter name="data" transfer-ownership="none">
    <doc xml:space="preserve">the pdf data contained in a char array</doc>
    <type name="utf8" c:type="char*"/>
</parameter>

TO:

<parameter name="data" transfer-ownership="none">
    <doc xml:space="preserve">the pdf data contained in a char array</doc>
    <array length="1" zero-terminated="0" c:type="gchar*">
        <type name="guint8"/>
    </array>
</parameter>

and then passing an array ref. Oddly enough, if I run the test script through
valgrind everything works (i.e. it prints the expected metadata and renders
the first page as PNG). This is true for any PDF. If I run the same command
without valgrind it segfaults. Apparently valgrind helps it survive
errors. This proves in any case that the PDF is being read.

The Valgrind log does list multiple memory access errors.  It looks like
poppler is reading from data that G:O:I has already freed.  The problem
seems to be that poppler_document_new_from_data does not copy the data
it is given but simply assumes that it will stay valid for the lifetime
of the document.  However, the corresponding argument is (implicitly)
marked as having transfer-ownership="none", so that G:O:I rightly
assumes it can discard the memory after the call.

Unfortunately, there is no support in gobject-introspection and hence in
G:O:I for this kind of memory semantic, as far as I know.
(transfer-ownership="full" would result in a working but leaky program.)

So I think at this point it would be best to create a bug report against
poppler.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]