Two issues with librsvg
- From: Oren Ben-Kiki <rsvg-oren ben-kiki org>
- To: gtk-app-devel-list gnome org
- Subject: Two issues with librsvg
- Date: Sun, 22 Oct 2017 08:05:49 +0300
My main issue is that librsvg seems to not find sub elements by id.
Specifically, rsvg_handle_has_sub returns false, and therefore querying for
the element's size and position fails. I'm probably doing something wrong
here... or is this a bug? I really want the ability to access sub-elements
size and position (by id or name or something along these lines), so any
advice/workaround to make this work would be appreciated.
The secondary issue is that librsvg causes memory leaks, or at least causes
valgrind to think there is such a leak. I can easily work around this with
a suppression file, but... Is there some additional cleanup function I
should call to release all allocated memory?
As you can see in the output (below), I am using version 2.40.13, if that
matters.
Here is the tiny test program:
--- cheese.cpp ---
#include <iostream>
#include <rsvg.h>
using namespace std;
static const char s_svg[] = R"EOF(
<svg>
<rect id='cheese' x='10' y='20' width='300' height='40'/>
</svg>
)EOF";
int main() {
cerr << "RSVG VERSION: " << LIBRSVG_VERSION << endl;
RsvgHandle* rsvg = rsvg_handle_new();
GError* error = nullptr;
if (!rsvg_handle_write(rsvg,
reinterpret_cast<const guchar*>(s_svg),
sizeof(s_svg) - 1,
&error)
|| !rsvg_handle_close(rsvg, &error)) { // <-- fixed
cerr << "Oops: " << error->message << endl;
g_error_free(error);
} else if (rsvg_handle_has_sub(rsvg, "cheese")) {
cerr << "Yummy cheese!" << endl;
} else {
cerr << "WHERE IS MY CHEESE?" << endl;
}
g_object_unref(rsvg);
return 0;
}
--- cheese.cpp ---
And a tinier shell script running it:
--- cheese.sh ---
#!/bin/sh
set -x
g++ \
-std=c++14 \
-isystem /usr/include/librsvg-2.0/librsvg \
-isystem /usr/include/glib-2.0 \
-isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include \
-isystem /usr/include/gdk-pixbuf-2.0 \
-isystem /usr/include/cairo \
-o cheese \
cheese.cpp \
-lrsvg-2 \
-lglib-2.0 \
-lgobject-2.0
valgrind --leak-check=full --track-origins=yes ./cheese
--- cheese.sh ---
The results are longer (I eliminated some of the repeated errors):
--- cheese.out ---
+ g++ -std=c++14 -isystem /usr/include/librsvg-2.0/librsvg -isystem
/usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include
-isystem /usr/include/gdk-pixbuf-2.0 -isystem /usr/include/cairo -o cheese
cheese.cpp -lrsvg-2 -lglib-2.0 -lgobject-2.0
+ valgrind --leak-check=full --track-origins=yes ./cheese
==20434== Memcheck, a memory error detector
==20434== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==20434== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==20434== Command: ./cheese
==20434==
RSVG VERSION: 2.40.13
WHERE IS MY CHEESE?
==20434==
==20434== HEAP SUMMARY:
==20434== in use at exit: 149,205 bytes in 361 blocks
==20434== total heap usage: 522 allocs, 161 frees, 170,579 bytes allocated
==20434==
==20434== 8 bytes in 1 blocks are possibly lost in loss record 17 of 349
==20434== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_
memcheck-amd64-linux.so)
==20434== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_
memcheck-amd64-linux.so)
==20434== by 0x50C07D7: g_realloc (in /lib/x86_64-linux-gnu/libglib-
2.0.so.0.4800.2)
==20434== by 0x53AE9D8: ??? (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x53B42CC: g_type_register_static (in
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.2)
==20434== by 0x53B4694: g_type_register_static_simple (in
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.2)
==20434== by 0x4E653F3: rsvg_handle_get_type (in
/usr/lib/x86_64-linux-gnu/librsvg-2.so.2.40.13)
==20434== by 0x4E658B5: rsvg_handle_new (in /usr/lib/x86_64-linux-gnu/
librsvg-2.so.2.40.13)
==20434== by 0x400B8B: main (in /home/oren/cheese)
==20434==
==20434== 8 bytes in 1 blocks are possibly lost in loss record 18 of 349
==20434== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_
memcheck-amd64-linux.so)
==20434== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_
memcheck-amd64-linux.so)
==20434== by 0x50C07D7: g_realloc (in /lib/x86_64-linux-gnu/libglib-
2.0.so.0.4800.2)
==20434== by 0x53AE9D8: ??? (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x53B42CC: g_type_register_static (in
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.2)
==20434== by 0x539353D: g_flags_register_static (in
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.2)
==20434== by 0x4E616A6: rsvg_handle_flags_get_type (in
/usr/lib/x86_64-linux-gnu/librsvg-2.so.2.40.13)
==20434== by 0x4E64FD3: ??? (in /usr/lib/x86_64-linux-gnu/
librsvg-2.so.2.40.13)
==20434== by 0x53B222C: g_type_class_ref (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x5398DAC: g_object_newv (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x5399533: g_object_new (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x4E658C9: rsvg_handle_new (in /usr/lib/x86_64-linux-gnu/
librsvg-2.so.2.40.13)
==20434==
==20434== 16 bytes in 1 blocks are possibly lost in loss record 124 of 349
==20434== at 0x4C2FB55: calloc (in /usr/lib/valgrind/vgpreload_
memcheck-amd64-linux.so)
==20434== by 0x50C0770: g_malloc0 (in /lib/x86_64-linux-gnu/libglib-
2.0.so.0.4800.2)
==20434== by 0x53AF522: ??? (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x53B3F90: g_type_register_fundamental (in
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.2)
==20434== by 0x539330B: ??? (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x538D177: ??? (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x40106B9: call_init.part.0 (dl-init.c:72)
==20434== by 0x40107CA: call_init (dl-init.c:30)
==20434== by 0x40107CA: _dl_init (dl-init.c:120)
==20434== by 0x4000C69: ??? (in /lib/x86_64-linux-gnu/ld-2.23.so)
==20434==
==20434== 16 bytes in 1 blocks are possibly lost in loss record 125 of 349
==20434== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_
memcheck-amd64-linux.so)
==20434== by 0x4C2FDEF: realloc (in /usr/lib/valgrind/vgpreload_
memcheck-amd64-linux.so)
==20434== by 0x50C07D7: g_realloc (in /lib/x86_64-linux-gnu/libglib-
2.0.so.0.4800.2)
==20434== by 0x53AF406: ??? (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x53B3F90: g_type_register_fundamental (in
/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.4800.2)
==20434== by 0x539330B: ??? (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x538D177: ??? (in /usr/lib/x86_64-linux-gnu/
libgobject-2.0.so.0.4800.2)
==20434== by 0x40106B9: call_init.part.0 (dl-init.c:72)
==20434== by 0x40107CA: call_init (dl-init.c:30)
==20434== by 0x40107CA: _dl_init (dl-init.c:120)
==20434== by 0x4000C69: ??? (in /lib/x86_64-linux-gnu/ld-2.23.so)
More leaked block messages removed here to keep this message short...
==20434== 15,334 (752 direct, 14,582 indirect) bytes in 1 blocks are
definitely lost in loss record 347 of 349
==20434== at 0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_
memcheck-amd64-linux.so)
==20434== by 0x6CAD97E: xmlNewParserCtxt (in /usr/lib/x86_64-linux-gnu/
libxml2.so.2.9.3)
==20434== by 0x6CC2C79: xmlCreatePushParserCtxt (in
/usr/lib/x86_64-linux-gnu/libxml2.so.2.9.3)
==20434== by 0x4E60AF5: rsvg_handle_write (in /usr/lib/x86_64-linux-gnu/
librsvg-2.so.2.40.13)
==20434== by 0x400BB7: main (in /home/oren/cheese)
==20434==
==20434== LEAK SUMMARY:
==20434== definitely lost: 752 bytes in 1 blocks
==20434== indirectly lost: 14,582 bytes in 16 blocks
==20434== possibly lost: 1,472 bytes in 22 blocks
==20434== still reachable: 130,607 bytes in 310 blocks
==20434== of which reachable via heuristic:
==20434== newarray : 1,536 bytes in 16
blocks
==20434== suppressed: 0 bytes in 0 blocks
==20434== Reachable blocks (those to which a pointer was found) are not
shown.
==20434== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==20434==
==20434== For counts of detected and suppressed errors, rerun with: -v
==20434== ERROR SUMMARY: 23 errors from 23 contexts (suppressed: 0 from 0)
--- cheese.out ---
Thanks,
Oren Ben-Kiki
[
Date Prev][
Date Next] [
Thread Prev][Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]