Commit Graph

38 Commits

Author SHA1 Message Date
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00:00
João Valverde 1fe4638648 wmem: Replace g_assert() with ws_assert() 2021-05-19 03:52:45 +01:00
Guy Harris 20800366dd HTTPS (almost) everywhere.
Change all wireshark.org URLs to use https.

Fix some broken links while we're at it.

Change-Id: I161bf8eeca43b8027605acea666032da86f5ea1c
Reviewed-on: https://code.wireshark.org/review/34089
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-07-26 18:44:40 +00:00
Gerald Combs 8f08a4e74e Try to discourage the use of APIs via counting.
Add the ability to specify maximum function counts for each group to
checkAPIs. Add maximum counts for the "termoutput" and "abort" groups
where needed. Show summaries in various checkAPI targets.

Switch uses of ws_g_warning back to plain g_warning.

Change-Id: I5cbddc8c671729e424eed8551f69116d16491976
Reviewed-on: https://code.wireshark.org/review/29721
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-09-19 16:07:03 +00:00
Dario Lombardo fc082fa2a9 wmem: use SPDX identifiers.
Change-Id: Iad9a7a8a26bc6a7189a4578dfbcec1c2b3cc376e
Reviewed-on: https://code.wireshark.org/review/25692
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 19:29:02 +00:00
Michael Mann e302d9fe4d Remove checkAPI warnings from wmem.
printf and g_warning are not allowed in epan or its subdirectories

Change-Id: I4c07a7258f4c9566384bef93af35c350b5c88758
Reviewed-on: https://code.wireshark.org/review/16801
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-08-01 04:21:22 +00:00
Michael Mann 4d4190f127 Have wmem conform to checkAPIs.pl
Yes, the rename of structure members is a bit hacky.
Yes, catering to Windows since "GLib's v*printf routines are
surprisingly slow on Windows".
But it does pass checkAPIs.pl

Change-Id: I5b1552472c83aa2e159f17b5b7eb70b37d03eff9
Reviewed-on: https://code.wireshark.org/review/15404
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-05-13 16:00:58 +00:00
Bill Meier 07698d536b Adjust some whitespace to match editor modelines.
Change-Id: Ia22cac3ebd7a454c156f98d967e6fd61f708a2b3
Reviewed-on: https://code.wireshark.org/review/4489
Reviewed-by: Bill Meier <wmeier@newsguy.com>
2014-10-06 02:55:49 +00:00
Jakub Zawadzki 5f239013e7 wmem: add new simple block allocator, use it in packet-scope.
For packet-scope allocation, there's no need to support realloc(), free()
cause memory will be garbage collected after packet dissection.

(and this allocator is much faster than full block allocator).

Change-Id: I73fdf708c3077f48f55bdcc71f4fa859e4ac2335
Reviewed-on: https://code.wireshark.org/review/1428
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-05-02 21:07:07 +00:00
Evan Huus 9ba4c6e091 Hash map implementation for wmem.
This has two expected uses:
- Many current users of wmem_tree don't actually need the predecessor lookup
  it provides (the lookup_le function family). A hash map provides straight
  insertion and lookup much more efficiently than a wmem_tree when predecessor
  lookup isn't needed.

- Many current users of glib's hash table and hash functions use untrusted data
  for keys, making them vulnerable to algorithmic complexity attacks. Care has
  been taken to make this implementation secure against such attacks, so it
  should be used whenever data is untrusted.

In my benchmarks it is measurably slower than GHashTable, but not excessively
so. Given the additional security it provides this seems like a reasonable
trade-off (and it is still faster than a wmem_tree).

Change-Id: I2d67a0d06029f14c153eaa42d5cfc774aefd9918
Reviewed-on: https://code.wireshark.org/review/1272
Reviewed-by: Evan Huus <eapache@gmail.com>
2014-04-23 12:42:26 +00:00
Alexis La Goutte 296591399f Remove all $Id$ from top of file
(Using sed : sed -i '/^ \* \$Id\$/,+1 d')

Fix manually some typo (in export_object_dicom.c and crc16-plain.c)

Change-Id: I4c1ae68d1c4afeace8cb195b53c715cf9e1227a8
Reviewed-on: https://code.wireshark.org/review/497
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-04 14:27:33 +00:00
Evan Huus 7b3dfaa525 As suggested separately by both Jakub and Anders: only read the
WIRESHARK_DEBUG_WMEM_OVERRIDE environment variable once in wmem_init, not every
time wmem_allocator_new is called. We currently create a new pinfo pool for
every packet we dissect, so this is a small performance win, especially when
getenv is slow (which may happen if a large number of environment variables are
set, such as when fuzz-testing).

svn path=/trunk/; revision=52634
2013-10-15 23:16:35 +00:00
Evan Huus 3c1e67c22d Send all alloc and free calls within wmem through wmem_alloc and wmem_free with
a NULL allocator. This gives us a single, central place to handle out-of-memory
errors (by, for example, throwing an exception) for basically all of epan.

The only remaining glib memory that is directly allocated is for the hash tables
used by the simple and strict allocators.

svn path=/trunk/; revision=51627
2013-09-01 13:37:38 +00:00
Evan Huus e13d73e038 Rework wmem scoping limits so that users can still get a handle to a pool when
it is out of scope, they just can't *allocate* in the pool. This is necessary
because file-scope trees (migrating from emem) are set up on program
initialization when there is no file in scope - they need to initialize with the
handle, they just won't use it until a file is actually in scope.

svn path=/trunk/; revision=50046
2013-06-19 18:28:13 +00:00
Evan Huus 881845a555 Scrap wmem_memdup, it's not actually as useful as I thought it would be.
svn path=/trunk/; revision=50009
2013-06-18 19:01:01 +00:00
Evan Huus 55264582be More callback tweaks, to permit unregistering a callback from the same place
it was originally registered.

svn path=/trunk/; revision=49969
2013-06-16 22:37:55 +00:00
Evan Huus 88c5b2e892 Rework the user callback code a bit to make it saner to use with the auto-reset
trees.

svn path=/trunk/; revision=49966
2013-06-16 22:07:24 +00:00
Evan Huus 226b39f1d7 Add memdup function to wmem.
svn path=/trunk/; revision=49857
2013-06-09 13:49:16 +00:00
Evan Huus 5426ba4e02 Minor refactor: make the framework responsible for allocating and freeing the
actual wmem_allocator_t structure. This simplifies the internal API and
deduplicates a few alloc/free calls in the individual allocator implementations.

I'd originally made the allocators responsible for this on purpose with the
idea that they'd be able to optimize something clever based on the type of
allocator, but that's clearly more work and complexity than it's worth given
the small number of allocators we create/destroy.

svn path=/trunk/; revision=49512
2013-05-22 15:42:12 +00:00
Evan Huus d860a01aaf Round two of wmem cleanup callbacks. While the emem tree behaviour will require
recurring callbacks, I suspect most other potential uses will be once-only, so
make that possible, and improve the documentation on the remaining issues.

Also separate out the code into its own files and the testing into its own
test case.

svn path=/trunk/; revision=49209
2013-05-08 01:14:01 +00:00
Evan Huus 2e92c6dfde Add user callbacks to wmem. This feature is a generic way to transparently mimic
the behaviour emem has for seasonal trees, which is that the master tree
structure is not actually seasonal - it is permanent. When the seasonal memory
pool is cleared, the root node pointer in all of these permanent trees is set
to NULL, and the pool takes care of actually freeing the nodes.

Wmem can now mimic this by allocating the tree header struct in epan_scope(),
allocating any node structs in file_scope(), and registering a callback on
file_scope() that NULLs the pointer in the epan_scope() header. Yes, this is
confusing, but it seemed simpler than adding manual callback registrations to
every single dissector that currently uses seasonal trees.

The callbacks may also be useful for other things that need cleanup (I'm
thinking resource handles stored in wmem memory that need to be fclosed or
what-have-you before they the handle is lost).

As indicated by the number of caveats in README.wmem, the implementation
probably needs a bit of work to make it safer/saner/more-useful. Thoughts
(or patches!) in this direction are more than welcome.

svn path=/trunk/; revision=49205
2013-05-07 19:23:10 +00:00
Evan Huus 8a874b238e Trivial tweaks to clean up cppcheck warnings.
svn path=/trunk/; revision=48435
2013-03-20 00:10:07 +00:00
Evan Huus cb679f279b If the requested wmem allocator is NULL, take that to mean manually-managed
memory. This permits using manually-scoped versions of certain wmem structures.

svn path=/trunk/; revision=47657
2013-02-14 16:23:22 +00:00
Evan Huus 681a3ad5a2 Handle NULL-pointers and 0-lengths in a much simpler allocator-agnostic way,
and document the fact that allocator authors don't have to care.

svn path=/trunk/; revision=47220
2013-01-23 01:11:36 +00:00
Evan Huus c25c5915c5 Add wrapper functions for realloc, free and gc, but don't expose them in the
header yet as not all allocators implement them.

svn path=/trunk/; revision=47219
2013-01-23 00:59:38 +00:00
Evan Huus 0c66691b92 Add a strict allocator that does canaries and various other things, for
platforms which don't have Valgrind.

Valgrind is still the better choice on platforms which support it.

svn path=/trunk/; revision=46828
2012-12-28 17:04:23 +00:00
Evan Huus 442b61d0a4 Change the format of the environment variable slightly to allow overriding
allocator choice to use any specific allocator, not just simple.

svn path=/trunk/; revision=46816
2012-12-27 22:51:33 +00:00
Evan Huus dc98756ca4 Store the type of each wmem allocator.
svn path=/trunk/; revision=46814
2012-12-27 22:31:42 +00:00
Guy Harris 292b386089 See if *this* squelches the MSVC errors.
svn path=/trunk/; revision=46611
2012-12-19 04:30:02 +00:00
Evan Huus 77d69b36b2 Try to fix windows builds - MSVC doesn't like g_assert_not_reached() ?
svn path=/trunk/; revision=46606
2012-12-19 01:08:21 +00:00
Evan Huus 5cf858ec52 Dispatch all allocator creations through a single function using an enum to
determine the desired type. This has two advantages over the old way:
 - just one environment variable for valgrind to override in order to guarantee
   that ALL allocators use memory it can track, and just one place to check that
   variable
 - allocator owners no longer have to include headers specific to their
   allocator, allowing them to change allocators without adjusting all their
   #includes

svn path=/trunk/; revision=46604
2012-12-19 00:43:36 +00:00
Evan Huus 561525cbb5 Rename allocator_glib to allocator_simple, since the block allocator also
uses glib and 'simple' describes the intention far better.

svn path=/trunk/; revision=46603
2012-12-18 23:36:45 +00:00
Evan Huus 82501433e3 Use const in wmem where possible.
svn path=/trunk/; revision=45976
2012-11-08 23:18:26 +00:00
Evan Huus 2737b7b7d3 Add wmem scopes for packet and file lifetimes. The file lifetime scope isn't
yet initialized because I can't figure out where the enter() and leave() calls
should go - the obvious place in packet.c causes a lot of assertion errors.

svn path=/trunk/; revision=45879
2012-11-03 15:49:15 +00:00
Evan Huus 6ef55f30d8 Rename wmem_permanent_scope -> wmem_epan_scope to reflect the fact that it
is technically scoped to the library, not the process. It's also shorter :)

svn path=/trunk/; revision=45877
2012-11-03 15:08:00 +00:00
Evan Huus b464dcd888 Create init and cleanup functions for wmem as a whole.
Call them from epan_init() and epan_cleanup().
Expose a permanent wmem scope for allocations that should only be freed when
epan is done (which is *not* necessarily when the program finishes).

svn path=/trunk/; revision=45805
2012-10-27 02:42:05 +00:00
Evan Huus 2ea364607a Make the allocator destructor part of wmem_allocator_t. This avoids two
potential bugs:
 - calling the wrong destroy function on an allocator
 - a pool allocator forgetting to call free_all on itself in the destructor

Also, fix potential typedef redefinition warning in wmem_allocator_glib.h

svn path=/trunk/; revision=45804
2012-10-27 02:29:46 +00:00
Evan Huus 84cc3daa3b Basic skeleton for wmem.
https://www.wireshark.org/lists/wireshark-dev/201210/msg00178.html

svn path=/trunk/; revision=45746
2012-10-24 02:04:40 +00:00