ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
July 17th, 2024 | 10:00am-11:55am SGT (UTC+8) | Online

Ethereal-dev: Re: [Ethereal-dev] Regarding Memory allocation

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: Mon, 07 Mar 2005 10:38:49 -0800
Jaap Keuter wrote:

From README.developer

   If you're setting it to a string you've constructed, or will be
   appending to the column later, use "col_add_str()".

So it all depends on how you _start_ filling the column. If it's already
filled using col_set_str(pinfo->cinfo, COL_INFO, "Blah"); you'll need to
clear it first, like so:

    col_clear(pinfo->cinfo, COL_INFO);

No, you don't need to - that note from README.developer is an optimization hint, not a strict requirement.

The problem is that "col_set_str()" just sets a pointer, it doesn't copy the string - but if you're going to append to the column, a copy has to be made of the string to a buffer, because "col_append_str()" and "col_append_fstr()" can't just append to the string passed in the "col_set_str()" call. If it's going to copy the string anyway, you might as well use "col_add_str()" and do the copy up front.