Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8998623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:03:43+00:00 2026-06-16T00:03:43+00:00

The following code compiles correctly and valgrind reports no leaks: # include <libxml/encoding.h> #

  • 0

The following code compiles correctly and valgrind reports no leaks:

# include <libxml/encoding.h>
# include <libxml/xmlwriter.h>

int main(void) {
  xmlTextWriterPtr XMLWriter = xmlNewTextWriterFilename("example.xml", 0);
  xmlTextWriterStartDocument(XMLWriter, NULL, NULL, NULL);
  xmlTextWriterEndDocument(XMLWriter);
  xmlFreeTextWriter(XMLWriter);
  xmlCleanupParser();
  return 0;
}

-----------------------------------------

==26059== HEAP SUMMARY:
==26059==     in use at exit: 0 bytes in 0 blocks
==26059==   total heap usage: 16 allocs, 16 frees, 4,774 bytes allocated
==26059== 
==26059== All heap blocks were freed -- no leaks are possible

Once the encoding is specified in the xmlNewTextWriterFilename call, however, hilary ensues:

# include <libxml/encoding.h>
# include <libxml/xmlwriter.h>

int main(void) {
  xmlTextWriterPtr XMLWriter = xmlNewTextWriterFilename("example.xml", 0);
  xmlTextWriterStartDocument(XMLWriter, NULL, "UTF-8", NULL);
  xmlTextWriterEndDocument(XMLWriter);
  xmlFreeTextWriter(XMLWriter);
  xmlCleanupParser();
  return 0;
}

-----------------------------------------

==26082== HEAP SUMMARY:
==26082==     in use at exit: 422 bytes in 17 blocks
==26082==   total heap usage: 36 allocs, 19 frees, 9,224 bytes allocated
==26082== 
==26082== 5 bytes in 1 blocks are still reachable in loss record 1 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x40EC23B: xmlStrndup (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x494942FF: ???
==26082== 
==26082== 6 bytes in 1 blocks are still reachable in loss record 2 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x40EC23B: xmlStrndup (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x37: ???
==26082== 
==26082== 6 bytes in 1 blocks are still reachable in loss record 3 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x40EC23B: xmlStrndup (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x39350048: ???
==26082== 
==26082== 7 bytes in 1 blocks are still reachable in loss record 4 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x40EC23B: xmlStrndup (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x45003630: ???
==26082== 
==26082== 9 bytes in 1 blocks are still reachable in loss record 5 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x40EC23B: xmlStrndup (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x454C3630: ???
==26082== 
==26082== 9 bytes in 1 blocks are still reachable in loss record 6 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x40EC23B: xmlStrndup (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x45423630: ???
==26082== 
==26082== 9 bytes in 1 blocks are still reachable in loss record 7 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x40EC23B: xmlStrndup (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x49494352: ???
==26082== 
==26082== 11 bytes in 1 blocks are still reachable in loss record 8 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x40EC23B: xmlStrndup (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x39353837: ???
==26082== 
==26082== 20 bytes in 1 blocks are still reachable in loss record 9 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x406E9D1: xmlNewCharEncodingHandler (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x406EB28: xmlInitCharEncodingHandlers (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x41B54D2: (below main) (libc-start.c:226)
==26082== 
==26082== 20 bytes in 1 blocks are still reachable in loss record 10 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x406E9D1: xmlNewCharEncodingHandler (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x406EB44: xmlInitCharEncodingHandlers (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x41B54D2: (below main) (libc-start.c:226)
==26082== 
==26082== 20 bytes in 1 blocks are still reachable in loss record 11 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x406E9D1: xmlNewCharEncodingHandler (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x406EB6C: xmlInitCharEncodingHandlers (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x41B54D2: (below main) (libc-start.c:226)
==26082== 
==26082== 20 bytes in 1 blocks are still reachable in loss record 12 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x406E9D1: xmlNewCharEncodingHandler (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x406EB94: xmlInitCharEncodingHandlers (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x41B54D2: (below main) (libc-start.c:226)
==26082== 
==26082== 20 bytes in 1 blocks are still reachable in loss record 13 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x406E9D1: xmlNewCharEncodingHandler (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x406EBB6: xmlInitCharEncodingHandlers (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x41B54D2: (below main) (libc-start.c:226)
==26082== 
==26082== 20 bytes in 1 blocks are still reachable in loss record 14 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x406E9D1: xmlNewCharEncodingHandler (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x406EBCC: xmlInitCharEncodingHandlers (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x41B54D2: (below main) (libc-start.c:226)
==26082== 
==26082== 20 bytes in 1 blocks are still reachable in loss record 15 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x406E9D1: xmlNewCharEncodingHandler (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x406EBE2: xmlInitCharEncodingHandlers (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x41B54D2: (below main) (libc-start.c:226)
==26082== 
==26082== 20 bytes in 1 blocks are still reachable in loss record 16 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x406E9D1: xmlNewCharEncodingHandler (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x406EC02: xmlInitCharEncodingHandlers (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x41B54D2: (below main) (libc-start.c:226)
==26082== 
==26082== 200 bytes in 1 blocks are still reachable in loss record 17 of 17
==26082==    at 0x402BE68: malloc (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==26082==    by 0x406EABE: xmlInitCharEncodingHandlers (in /usr/lib/i386-linux-gnu/libxml2.so.2.7.8)
==26082==    by 0x41B54D2: (below main) (libc-start.c:226)
==26082== 
==26082== LEAK SUMMARY:
==26082==    definitely lost: 0 bytes in 0 blocks
==26082==    indirectly lost: 0 bytes in 0 blocks
==26082==      possibly lost: 0 bytes in 0 blocks
==26082==    still reachable: 422 bytes in 17 blocks
==26082==         suppressed: 0 bytes in 0 blocks

What do? This is homework stuff – can’t ignore valgrind results.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:03:44+00:00Added an answer on June 16, 2026 at 12:03 am

    Add a call to xmlCleanupCharEncodingHandlers() right before the call to xmlCleanupParser().

    On my Mac OS 10.7.5 dev machine (libxml 20703), this fixes the reported “still reachable” leaks in libxml2.

    By the way, ??? means that the debugging symbols for the object file are not available. It can be very helpful when tracking down memory leaks to have this information. The procedure for installing debugging information depends on the Linux distribution. On Ubuntu, for example, you can install the libxml2 debugging information with sudo apt-get install libxml2-dbg. See https://live.gnome.org/GettingTraces/DistroSpecificInstructions

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following source code compiles correctly with Visual Studio 2010: namespace NS { class
The following code: #include <stdio.h> typedef union { int n; char *s; } val_t;
The following code compiles correctly under VC++ 8 on XPSP3, but running it causes
How does the following code compile correctly, #include <stdio.h> #define stringer( x ) printf_s(
Please consider the following code: #include <iostream> #include <typeinfo> template< typename Type > void
The following code compiles in Visual C++ and gcc, but fails with Code Warrior
the following code compiles with Visual Studio 2008 but not with g++ on Mac
I have the following code that compiles and works well: template<typename T> T GetGlobal(const
I came across the following code that compiles fine (using Visual Studio 2005): SomeObject
How is it possible that following code even compiles? As far as I can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.