memory leaks in OptionEntry::add_entry



Hi,

I'm trying to see how to use the Glib::OpenEntry.

When I compile and run the attached program, valgrind complains on memory 
leaks when I use "OptionGroup::add_entry (const OptionEntry& entry, 
vecustrings& arg)".

Is this a real leak?

$ valgrind --leak-check=full options -b -s xxx -v aaa
...
==25883== 16 (12 direct, 4 indirect) bytes in 2 blocks are definitely lost in 
loss record 15 of 71
==25883==    at 0x4022AB8: malloc (vg_replace_malloc.c:207)
==25883==    by 0x4A0471C: g_malloc (in /usr/lib/libglib-2.0.so.0.1600.3)
==25883==    by 0x4959A9C: 
Glib::OptionGroup::CppOptionEntry::set_c_arg_default(void*) 
(in /usr/lib/libglibmm-2.4.so.1.0.24)
==25883==    by 0x4959F43: 
Glib::OptionGroup::add_entry_with_wrapper(Glib::OptionEntry const&, 
GOptionArg, void*) (in /usr/lib/libglibmm-2.4.so.1.0.24)
==25883==    by 0x495A142: Glib::OptionGroup::add_entry(Glib::OptionEntry 
const&, std::vector<Glib::ustring, std::allocator<Glib::ustring> >&) 
(in /usr/lib/libglibmm-2.4.so.1.0.24)
==25883==    by 0x804A688: main (main.cc:40)
==25883==
...
==25883== LEAK SUMMARY:
==25883==    definitely lost: 12 bytes in 2 blocks.
==25883==    indirectly lost: 4 bytes in 1 blocks.
==25883==      possibly lost: 25,976 bytes in 41 blocks.
==25883==    still reachable: 177,160 bytes in 3,359 blocks.
==25883==         suppressed: 0 bytes in 0 blocks.
==25883== Reachable blocks (those to which a pointer was found) are not shown.
==25883== To see them, rerun with: --leak-check=full --show-reachable=yes

Are the 'possibly lost' and 'still reachable' important? If not, can they be 
suppressed somehow?

Thanx,

Johnny
#include <gtkmm.h>
#include <iostream>
#include <vector>

int main(int argc, char *argv[])
{
	bool b = false;
	int x = 0;
	Glib::ustring s;
	std::vector<Glib::ustring> v;

	Glib::OptionEntry oeb;
	oeb.set_long_name("bool");
	oeb.set_short_name('b');
	oeb.set_description("option bool");
	oeb.set_arg_description("BOOL");

	Glib::OptionEntry oex;
	oex.set_long_name("int");
	oex.set_short_name('x');
	oex.set_description("option integer");
	oex.set_arg_description("INT");

	Glib::OptionEntry oes;
	oes.set_long_name("str");
	oes.set_short_name('s');
	oes.set_description("option string");
	oes.set_arg_description("STR");

	Glib::OptionEntry oev;
	oev.set_long_name("vector");
	oev.set_short_name('v');
	oev.set_description("option vector");
	oev.set_arg_description("STR");

	Glib::OptionGroup og("og", "og description", "help og");
	og.add_entry(oeb, b);
	og.add_entry(oex, x);
	og.add_entry(oes, s);
	og.add_entry(oev, v);

	Glib::OptionContext octx("000 parameter string 000");
	octx.set_summary("111 summary 111");
	octx.set_description("222 description 222");

	octx.add_group(og);

	try
	{
	    Gtk::Main kit(argc, argv, octx);

	    std::cout << "option oeb: " << b << std::endl;
	    std::cout << "option oex: " << x << std::endl;
	    std::cout << "option oes: " << s << std::endl;

	    for(int i=0; i < v.size(); ++i)
	    {
	    	std::cout << "option oev[" << i << "]: " << v[i] << std::endl;
	    }

	    for(int i=0; i < argc; ++i)
	    {
	    	std::cout << "argv[" << i << "]: " << argv[i] << std::endl;
	    }
	}
	catch(Glib::OptionError& err)
	{
		std::cout << err.what() << "\n\n"
			<< octx.get_help() << "\n";
	}

    return 0;
}

Attachment: signature.asc
Description: This is a digitally signed message part.



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