ANNOUNCEMENT: Live Wireshark University & Allegro Packets online APAC Wireshark Training Session
April 17th, 2024 | 14:30-16:00 SGT (UTC+8) | Online

Wireshark-dev: Re: [Wireshark-dev] Question regarding emem -> wmem conversion

From: Evan Huus <eapache@xxxxxxxxx>
Date: Fri, 13 Sep 2013 08:30:54 -0400
On 2013-09-13, at 7:55 AM, Dario Lombardo <dario.lombardo.ml@xxxxxxxxx> wrote:

> I'm trying to address se_alloc() calls. If I change this:
> 
> Index: packet-infiniband_sdp.c
> ===================================================================
> --- packet-infiniband_sdp.c	(revision 52002)
> +++ packet-infiniband_sdp.c	(working copy)
> @@ -31,6 +31,7 @@
>  #include <epan/packet.h>
>  #include <epan/prefs.h>
>  #include <epan/conversation.h>
> +#include <epan/wmem/wmem.h>
>  #include <stdlib.h>
>  #include <errno.h>
>  
> @@ -529,8 +530,8 @@
>          heur_dissector_add("infiniband.mad.cm.private", dissect_ib_sdp, proto_ib_sdp);
>  
>          /* allocate enough space in the addresses to store the largest address (a GID) */
> -        manual_addr_data[0] = se_alloc(GID_SIZE);
> -        manual_addr_data[1] = se_alloc(GID_SIZE);
> +        manual_addr_data[0] = wmem_alloc(wmem_file_scope(), GID_SIZE);
> +        manual_addr_data[1] = wmem_alloc(wmem_file_scope(), GID_SIZE);
>  
>          initialized = TRUE;
>      }
> @@ -567,4 +568,3 @@
>  
>      }
>  }
> -
> 
> tshark -v crashes. What is wrong with my patch?

Apparently there is no file in scope when that code is run. Depending on the necessary lifetime of the memory, it may make sense to replace it with epan scoped memory (the lifetime of the program, basically) or manually managed memory if the lifetime is something else.