Ethereal-dev: Re: [Ethereal-dev] Patches to correct memory leaks

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Guy Harris <gharris@xxxxxxxxx>
Date: Fri, 07 Jan 2005 02:55:03 -0800
Maynard, Chris wrote:
** Attached are proposed patches to several dissectors that appear to have memory leaks due to not freeing memory allocated after calls to ****tvb_get_string()****, ****tvb_get_stringz()****, and ****tvb_fake_unicode()****.

I've checked some changes in; in other cases, where the string was only being used as the argument to a "%s", I've used "tvb_format_text()" instead, so that if the string contains non-printable characters (either because the sending implementation put them in, or we're dissecting traffic that *isn't* really traffic for that protocol, or there's a bug in the dissector and it's dissecting characters not part of the string), we don't put random non-printable bytes into the displayed or printed text.

BTW: It was quite a tedious task to check for these leaks, and I fear that leaks like this will continue to creep in, even if we’ve somehow managed to find them all for the time being.

Having a higher-level language for writing many dissectors (e.g., NetPDL:

	http://analyzer.polito.it/30alpha/docs/dissectors/NetPDL.htm

or some syntactically-sweetened version thereof), with a script to translate the higher-leven language to C code - and using existing higher-level languages, such as ASN.1 - might help, as it might avoid leaky code being generated (modulo deficiencies in the translators - and modulo bugs in infrastructure the generated code uses, such as the one you found in packet-per.c, although once you've fixed that bug you've fixed it in *all* dissectors for PER-based protocols).