Wireshark-dev: Re: [Wireshark-dev] Out of Memory issue
From: "Kumar, Hemant" <kumarh@xxxxxxxxxxxx>
Date: Sat, 26 Jul 2008 00:18:05 -0700
Hello Harris

To clarify

The following code snippet do not works:---


>                   if (check_col(pinfo->cinfo,COL_INFO))
>                   {
>
>                       temp_str = ep_alloc(STRING_BUFFER);
>                       printf( "[%s] %s ", message->direction,
> message->message_type);
>                   }



And the following does work with only ep_alloc()
                   if (check_col(pinfo->cinfo,COL_INFO))
                   {

                       temp_str = ep_alloc(STRING_BUFFER);
                   }


So it seems some memeory allocation error with message->direction, message->message_type is occuring .But actually the message just points to a
Static array element of message type structure so there is no need for
Deallocation for static array or is it?

Thanks
Hemant



-----Original Message-----
From: wireshark-dev-bounces@xxxxxxxxxxxxx [mailto:wireshark-dev-bounces@xxxxxxxxxxxxx] On Behalf Of Guy Harris
Sent: Friday, July 25, 2008 3:45 PM
To: Developer support list for Wireshark
Subject: Re: [Wireshark-dev] Out of Memory issue


On Jul 25, 2008, at 3:23 PM, Kumar, Hemant wrote:

> Even if I comment  as shown below and add a simple printf statement
> it fails but if I just keep the first line ep_alloc() and comment
> everything
> With no printf addition then it works.:--
>
>                   if (check_col(pinfo->cinfo,COL_INFO))
>                   {
>
>                       temp_str = ep_alloc(STRING_BUFFER);
>                       printf( "[%s] %s ", message->direction,
> message->message_type);
>          //           g_snprintf( temp_str, sizeof(temp_str), "[%s]
> %s ", message->direction, message->message_type);
>          //          col_add_str(pinfo->cinfo, COL_INFO, temp_str);
>
>                   }

So that sample does, or doesn't, work?

If it doesn't work, is the code that does work

                   if (check_col(pinfo->cinfo,COL_INFO))
                   {

                       temp_str = ep_alloc(STRING_BUFFER);
          //             printf( "[%s] %s ", message->direction,
message->message_type);
          //           g_snprintf( temp_str, sizeof(temp_str), "[%s]
%s ", message->direction, message->message_type);
          //          col_add_str(pinfo->cinfo, COL_INFO, temp_str);

                   }

or, equivalently:

                   if (check_col(pinfo->cinfo,COL_INFO))
                   {

                       temp_str = ep_alloc(STRING_BUFFER);
          //           g_snprintf( temp_str, sizeof(temp_str), "[%s]
%s ", message->direction, message->message_type);
          //          col_add_str(pinfo->cinfo, COL_INFO, temp_str);

                   }


(i.e., "just keep the first line ep_alloc()" and "comment everything
with no printf addition"?

By the way, there's a "col_add_fstr()" routine which takes a format
string and an argument list, so you can just do

                if (check_col(pinfo->cinfo, COL_INFO))
                {
                        col_add_fstr(pinfo->cinfo, COL_INFO, "[%s] %s ", message-
 >direction, message->message_type);
                }

You also don't have to do

                   if (check_col(pinfo->cinfo,COL_INFO))
                   {
                         col_clear(pinfo->cinfo,COL_INFO);
                   }

if, immediately after that, you're going to set the string.
_______________________________________________
Wireshark-dev mailing list
Wireshark-dev@xxxxxxxxxxxxx
https://wireshark.org/mailman/listinfo/wireshark-dev