This is a static archive of our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

Converting se_alloc() to wmem

0

In my old plugin code(1.6), the following lines of codes has been used inside proto_register_myPlugin Routine to initialize Array to Zero. I know that se_alloc is invalid now and wmem_alloc should be used. I have tried different ways. It just isn't working. Could someone please help me? Thanks

msc_to_cmd_database = (void*) se_alloc(255 * (sizeof(proto_tree) + 1));
memset(msc_to_cmd_database, 0, 255 * (sizeof(proto_tree) + 1));

(in .h file _>) static struct msc_to_cmd_relation_struct { guint8 ife_command; }*msc_to_cmd_database;

asked 13 Feb ‘17, 04:43

xaheen's gravatar image

xaheen
71141519
accept rate: 50%

edited 13 Feb ‘17, 09:37

Guy%20Harris's gravatar image

Guy Harris ♦♦
17.4k335196

Could you please clarify what is not working exactly? Are you triggering an assert because you are not using the right memory scope?

(13 Feb ‘17, 06:35) Pascal Quantin

@Pascal Quantin I am upgrading the dissector for wireshark 2.2 I am supposed to use wmem, which I have used but it is not compiling and not even showing any error. What could be the wmem_alloc Version for the above code. Thanks for your Response

(13 Feb ‘17, 06:43) xaheen


One Answer:

1

Give a try to:

msc_to_cmd_database = (struct msc_to_cmd_relation_struct*) wmem_alloc0(wmem_epan_scope(), 255 * (sizeof(proto_tree) + 1));

But was this memory freed somewhere else in the code?

answered 13 Feb '17, 07:12

Pascal%20Quantin's gravatar image

Pascal Quantin
5.5k1060
accept rate: 30%

@Pascal Quantin wow! it worked! thanks. No, I havent freed the Memory. how do I do it?

(13 Feb '17, 07:23) xaheen

If it is not required to free the memory in your plugin, why allocate it dynamically and not define the array once for all?

(13 Feb '17, 07:43) Pascal Quantin