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] Banish ALL kinds of g_assert from epan (dissector) code?

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: Tue, 22 Mar 2005 17:45:29 -0800
LEGO wrote:
At this point I have few questions:

Note that Ulf's changes don't increase the relevance of these questions very much - *existing* code shouldn't assume subdissectors won't throw exceptions, so they were relevant before his changes.

- How do I malloc something so that it can be freed after an exception?

	xxx = g_malloc(...);
	CLEANUP_PUSH(g_free, xxx);

- How do I free what's being malloced that way?

	CLEANUP_CALL_AND_POP;

- Since some of the proto.c functions that THROW are used during setup
by some dissectors (I know MATE does for sure I think others do as
well); I wonder on what would happen if an exception is thrown.  Are
we already in a TRY frame during protocol registration/handoff and
preferences setup or should that be created in case something is
thrown during that phase?

"Setup" in the sense of the initialization done in the registration routine or the register-handoff routine?

If so, what proto.c functions that throw exceptions are used in the registration routine?

- I have another more general question related to the TRY-CATCH
mechanism that ethereal uses. can TRY "blocks" nest? (is there a stack
for long jumps?)

There is no stack for the C longjmp() function.

There *is* a stack for exceptions, each element of which contains a jmp_buf.