[prev in list] [next in list] [prev in thread] [next in thread] 

List:       wireshark-dev
Subject:    [Wireshark-dev] Memory Leak?
From:       "phishjam78 () yahoo ! com" <phishjam78 () yahoo ! com>
Date:       2009-07-30 23:38:15
Message-ID: 762445.26181.qm () web56002 ! mail ! re3 ! yahoo ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


I have been rolling my own version of "tshark" for a project.  I needed to do a few \
things differently, but wanted all the awesomness of the dissectors to work for me.  \
I have been looking at a few reported memory leaks (via Valgrind) and there are two \
that are really stumping me.  I am wondering if I am setting up someting wrong or not \
freeing something properly.

I build my edt pointer by:
edt = epan_dissect_new(create_proto_tree, TRUE);
Then I fill out requisite information, call the ep_free_all() and then dissect_ip.  \
Within dissect_ip()... if (tree) {
    ti = proto_tree_add_item(tree, proto_ip, tvb, offset, hlen, FALSE);
the "ti" pointer has a frame_info that never seems to get free'd.  If I manually try \
to free it after dissection, bad things happen. Then, once dissect_ip returns, I get \
my data out, and call the contents of epan_dissect_free(). /* Free the data sources \
list. */  free_data_sources(&edt->pi);

	/* Free all tvb's created from this tvb, unless dissector
	 * wanted to store the pointer (in which case, the dissector
	 * would have incremented the usage count on that tvbuff_t*) */
	tvb_free_chain(edt->tvb);

	if (edt->tree) {
		proto_tree_free(edt->tree);
	}

	g_free(edt);
From there, edt->tree doesn't seem to have its members properly deleted.  The "rest" \
of the tree seems to go away, but not the "root" node itself. When running for only a \
few minutes, I can see the memory creep up and multiple controlled valgrind runs \
confirmed what I am seeing.  I am a bit stumped.   Could I not be setting up the edt \
pointer correctly or fillint out its members correctly?   Is there something else I \
need to do when cleaning up?   Do I HAVE to use the tap_queue_init(edt) and \
tap_push_tapped_queue(edt) functions? Overall, the app works perfectly...except for \
some pesky memory leaks.  Any and all help/ideas would be greatly appreciated!

- John


      


[Attachment #5 (text/html)]

<html><head><style type="text/css"><!-- DIV {margin:0px;} \
--></style></head><body><div style="font-family:'times new roman', 'new york', times, \
serif;font-size:12pt"><div><font class="Apple-style-span" face="arial, helvetica, \
sans-serif">I have been rolling my own version of "tshark" for a project. &nbsp;I \
needed to do a few things differently, but wanted all the awesomness of the \
dissectors to work for me. &nbsp;I have been looking at a few reported memory leaks \
(via Valgrind) and there are two that are really stumping me. &nbsp;I am wondering if \
I am setting up someting wrong or not freeing something \
properly.</font></div><div><font class="Apple-style-span" face="arial, helvetica, \
sans-serif"><br></font></div><div><font class="Apple-style-span" face="arial, \
helvetica, sans-serif">I build my edt pointer by:</font></div><div><span \
class="Apple-style-span" style="color: rgb(68, 68, 68); font-family: \
-webkit-monospace; font-size: 13px; white-space: pre;  "><pre><span \
class="Apple-tab-span" style="white-space:pre">	</span>edt = \
epan_dissect_new(create_proto_tree, TRUE);</pre><pre><font class="Apple-style-span" \
face="arial, helvetica, sans-serif"><span class="Apple-style-span" style="font-size: \
medium;">Then I fill out requisite information, call the&nbsp;ep_free_all() and then \
dissect_ip.  Within dissect_ip()...</span></font></pre><pre><font \
class="Apple-style-span" face="arial" size="4"><span class="Apple-style-span" \
style="font-size: 16px;"><span class="Apple-style-span" style="font-family: \
-webkit-monospace; font-size: 13px; "><pre>  <span class="Apple-tab-span" \
style="white-space:pre">	</span><b><font color="#A020F0">if</font></b> (tree) {  \
<span class="Apple-tab-span" style="white-space:pre">		</span>ti = \
proto_tree_add_item(tree, proto_ip, tvb, offset, hlen, FALSE);</pre><pre><span \
class="Apple-style-span" style="font-size: medium;"><font class="Apple-style-span" \
face="arial, helvetica, sans-serif">the "ti" pointer has a frame_info that never \
seems to get free'd.  If I manually try to free it after dissection, bad things \
happen.</font></span></pre><pre><span class="Apple-style-span" style="font-size: \
medium;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">Then, \
once dissect_ip returns, I<span class="Apple-style-span" style="font-family: \
-webkit-monospace; font-size: 13px; "><font class="Apple-style-span" face="arial, \
helvetica, sans-serif"><span class="Apple-style-span" style="font-size: medium;"> get \
my data out, and call the contents of epan_dissect_free()</span></font><span \
class="Apple-style-span" style="font-size:  \
medium;">.</span></span></font></span></pre></span></span></font></pre><pre><pre><i><font \
color="#B22222"><span class="Apple-tab-span" style="white-space:pre">	</span>/* Free \
the data sources list. */</font></i>  free_data_sources(&amp;edt-&gt;pi);

	<i><font color="#B22222">/* Free all tvb's created from this tvb, unless dissector
	 * wanted to store the pointer (in which case, the dissector
	 * would have incremented the usage count on that tvbuff_t*) */</font></i>
	tvb_free_chain(edt-&gt;tvb);

	<b><font color="#A020F0">if</font></b> (edt-&gt;tree) {
		proto_tree_free(edt-&gt;tree);
	}

	g_free(edt);</pre></pre><pre><span class="Apple-style-span" style="font-size: \
medium;"><font class="Apple-style-span" face="arial, helvetica, sans-serif">From \
there, edt-&gt;tree doesn't seem to have its members properly deleted.  The "rest" of \
the tree seems to go away, but not the "root" node \
itself.</font></span></pre><pre><font class="Apple-style-span" face="arial" \
size="4"><span class="Apple-style-span" style="font-size: 16px;">When running for \
only a few minutes, I can see the memory creep up and multiple controlled valgrind \
runs confirmed what I am seeing.  I am a bit stumped. \
&nbsp;</span></font></pre><pre><font class="Apple-style-span" face="arial" \
size="4"><span class="Apple-style-span" style="font-size: 16px;">Could I not be \
setting up the edt pointer correctly or fillint out its members correctly? \
&nbsp;</span></font></pre><pre><font class="Apple-style-span" face="arial" \
size="4"><span class="Apple-style-span" style="font-size: 16px;">Is  there something \
else I need to do when cleaning up? &nbsp;</span></font></pre><pre><font \
class="Apple-style-span" face="arial" size="4"><span class="Apple-style-span" \
style="font-size: 16px;">Do I HAVE to use the <span class="Apple-style-span" \
style="font-family: -webkit-monospace; font-size: 13px; ">tap_queue_init(edt) <span \
class="Apple-style-span" style="font-size: medium;"><font class="Apple-style-span" \
face="arial, helvetica, sans-serif">and </font></span>tap_push_tapped_queue(edt) \
</span><span class="Apple-style-span" style="font-size: medium;"><font \
class="Apple-style-span" face="arial, helvetica, \
sans-serif">functions?</font></span></span></font></pre><pre><font \
class="Apple-style-span" face="arial" size="4"><span class="Apple-style-span" \
style="font-size: 16px;">Overall, the app works perfectly...except for some pesky \
memory leaks.  Any and all help/ideas would be greatly \
appreciated!</span></font></pre><pre><font class="Apple-style-span"  face="arial" \
size="4"><span class="Apple-style-span" style="font-size: \
16px;"><br></span></font></pre><pre><font class="Apple-style-span" face="arial" \
size="4"><span class="Apple-style-span" style="font-size: 16px;">- \
John</span></font></pre><pre><font class="Apple-style-span" face="arial" \
size="4"><span class="Apple-style-span" style="font-size: \
16px;"><br></span></font></pre><pre><br></pre></span></div><div \
style="position:fixed"></div></div><br>

      </body></html>



___________________________________________________________________________
Sent via:    Wireshark-dev mailing list <wireshark-dev@wireshark.org>
Archives:    http://www.wireshark.org/lists/wireshark-dev
Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev
             mailto:wireshark-dev-request@wireshark.org?subject=unsubscribe

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic