1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-12-24 21:33:51 +03:00
Commit Graph

95 Commits

Author SHA1 Message Date
Nick Wellnhofer
e75e878e02 doc: Update and fix documentation 2024-05-20 14:23:39 +02:00
Nick Wellnhofer
1cdfece12b memory: Remove memory debugging
This is useless compared to sanitizers or valgrind and has a
considerable performance impact if enabled accidentally.
2024-04-28 20:42:55 +02:00
Nick Wellnhofer
ecb4c9fb28 misc: Improve error handling
Remove calls to generic error handler or use stderr for

- legacy deprecation warnings
- nanohttp, nanoftp in standalone mode
- memory debug messages

Use xmlRaiseMemoryError.

Remove TODO macro.

Don't raise errors in xmlmodule.c.
2023-12-21 15:02:24 +01:00
Nick Wellnhofer
fc26934eb0 memory: Fix memory debugging with Windows threads
On Windows, malloc hooks can be called after the final call to
xmlCleanupParser in various tests. This means that xmlMemMutex can still
be accessed if memory debugging is enabled, so the mutex should not be
cleaned.

This also means that tests may report spurious memory leaks on Windows.

The old implementation avoided the issue by keeping track of all
global state objects in a doubly linked list, so they could be cleaned
during xmlCleanupParser.

But as far as I can tell all memory will be freed eventually, so this is
mostly an issue with our test suite.
2023-09-21 23:29:18 +02:00
Nick Wellnhofer
d1336fd393 globals: Move malloc hooks back to xmlmemory.h 2023-09-20 22:06:49 +02:00
Nick Wellnhofer
4e1c13ebfd debug: Remove debugging code
This is barely useful these days and only clutters the code base.
2023-09-19 17:35:09 +02:00
Nick Wellnhofer
886bf4e63b Stop calling xmlMemoryDump
This was used to check for memory leaks but could potentially create a
.memdump file. These days, there are better ways to check for memory
leaks.
2023-04-30 15:48:41 +02:00
Nick Wellnhofer
d7daf9fd96 xmllint: Fix use-after-free with --maxmem
Fixes #498.
2023-03-14 14:55:34 +01:00
Nick Wellnhofer
a77e32736c xmlmemory.c: Remove xmlMemContentShow
This debug function was always unsafe and hard-coded pointer sizes to
32 bits. Instead of attempting a fix, remove it completely. These days,
tools like ASan are much better to debug memory issues.

Fixes #214.
2022-12-08 19:45:40 +01:00
Nick Wellnhofer
1966382b34 memory: Don't use locks in xmlMemUsed
The Python tests call xmlMemUsed after xmlCleanupParser which doesn't
work with statically allocated mutexes. This is only used for debugging,
so a lock isn't necessary.
2022-11-27 02:11:07 +01:00
Nick Wellnhofer
65d381f32c threads: Allocate mutexes statically 2022-11-25 15:12:56 +01:00
Nick Wellnhofer
2e9aeecb4e memory: Remove xmlMemInitialized
Call xmlInitParser instead of xmlInitMemoryInternal.
2022-11-25 15:02:04 +01:00
Nick Wellnhofer
9dbf137455 parser: Make some module init/cleanup functions private 2022-11-25 15:02:04 +01:00
Nick Wellnhofer
40483d0ce2 Deprecate module init and cleanup functions
These functions shouldn't be part of the public API. Most init
functions are only thread-safe when called from xmlInitParser. Global
variables should only be cleaned up by calling xmlCleanupParser.
2022-03-06 15:59:43 +01:00
Nick Wellnhofer
ebb1797030 Remove unneeded #includes 2022-03-04 22:11:49 +01:00
Nick Wellnhofer
72119afe00 Don't check for standard C89 library functions
Don't check for

- fprintf
- localtime
- printf
- rand
- sprintf
- srand
- sscanf
- strftime
- time
- vfprintf
- vsprintf

If the C99 functions snprintf and vsnprintf are missing, Trio is
enabled.
2022-03-02 01:14:08 +01:00
Nick Wellnhofer
776d15d383 Don't check for standard C89 headers
Don't check for

- ctype.h
- errno.h
- float.h
- limits.h
- math.h
- signal.h
- stdarg.h
- stdlib.h
- string.h
- time.h

Stop including non-standard headers

- malloc.h
- strings.h
2022-03-02 00:43:54 +01:00
Nick Wellnhofer
346c3a930c Remove elfgcchack.h
The same optimization can be enabled with -fno-semantic-interposition
since GCC 5. clang has always used this option by default.
2022-02-20 21:49:04 +01:00
Nick Wellnhofer
f4a74bf0ae Add suffix to unsigned constant in xmlmemory.c
Avoids an integer conversion warning with UBSan.
2022-01-25 03:07:30 +01:00
Nick Wellnhofer
20c60886e4 Fix typos
Resolves #133.
2020-03-08 17:41:53 +01:00
Nick Wellnhofer
d422b954be Fix pointer/int cast warnings on 64-bit Windows
On 64-bit Windows, `long` is 32 bits wide and can't hold a pointer.
Switch to ptrdiff_t instead which should be the same size as a pointer
on every somewhat sane platform without requiring C99 types like
intptr_t.

Fixes bug 788312.

Thanks to J. Peter Mugaas for the report and initial patch.
2017-10-09 13:47:49 +02:00
Nick Wellnhofer
1a595cd173 Fix cast-align warnings
- Suppress warnings in xmlmemory.c by casting to 'void *'.
- Remove unneeded cast in xmlschemas.c that caused a macro precedence
  error.
- Add dummy fields to short structs in xmlschemas.c. This increases the
  size of the structs, but I can't see a better solution without using
  C11's _Alignof operator.

There are still a couple of cast-align warnings in encoding.c. These
are legitimate portability issues that can't be fixed without reworking
the conversion functions.
2017-06-17 14:17:27 +02:00
Nick Wellnhofer
ed48d65b4d Fix copy-paste errors in error messages
Thanks to David Kilzer for the review.
2017-06-11 17:12:21 +02:00
Nick Wellnhofer
897dffbae3 Check for integer overflow in memory debug code
Fixes bug 783026.

Thanks to Pranjal Jumde for the report.
2017-06-06 13:21:14 +02:00
David Kilzer
886529b56c Unsigned addition may overflow in xmlMallocAtomicLoc()
For https://bugzilla.gnome.org/show_bug.cgi?id=764616

This code is used only if turning memory allocation debug
in configure with --with-mem-debug, which should never happen
in real life, so not a serious issue.

* xmlmemory.c:
(MAX_SIZE_T): Macro to define maximum value of size_t.
(xmlMallocAtomicLoc): Add bounds check.  Fix description and use
the correct function name in another error message.
2016-05-23 09:23:22 +08:00
Martin von Gagern
8985cde709 xmlMemUsed is not thread-safe
For https://bugzilla.gnome.org/show_bug.cgi?id=747437
just use the mutex to protect access to those variables
2015-04-13 16:32:14 +08:00
Yegor Yefremov
7446445dec xmlmemory: handle realloc properly
If realloc fails, free original pointer.

Signed-off-by: Yegor Yefremov <yegorslists@googlemail.com>
2014-10-13 20:46:37 +08:00
Gaurav Gupta
b8480ae781 Remove a couple of dead conditions
For https://bugzilla.gnome.org/show_bug.cgi?id=733711
2014-07-26 21:14:53 +08:00
Gaurav
7966a761b7 Avoid Possible null pointer dereference in memory debug mode
Fix a use before check on pointer
For https://bugzilla.gnome.org/show_bug.cgi?id=729849
2014-05-09 17:00:08 +08:00
Daniel Veillard
f8e3db0445 Big space and tab cleanup
Remove all space before tabs and space and tabs at end of lines.
2012-09-11 13:26:36 +08:00
Stefan Kost
ecb5d5afdc xmlmemory: add a cast as size_t has no portable printf modifier
Also use %lu as that is more appropriate for size_t.
2011-05-09 11:49:52 +03:00
Daniel Veillard
f63085de5e port patch from Marcus Meissner to add gcc checking for printf like
* include/libxml/parser.h include/libxml/xmlwriter.h
  include/libxml/relaxng.h include/libxml/xmlversion.h.in
  include/libxml/xmlwin32version.h.in include/libxml/valid.h
  include/libxml/xmlschemas.h include/libxml/xmlerror.h:
  port patch from Marcus Meissner to add gcc checking for
  printf like functions parameters, should fix #65068
* doc/apibuild.py doc/*: modified the script accordingly
  and regenerated
* xpath.c xmlmemory.c threads.c: fix a few warnings
Daniel

svn path=/trunk/; revision=3813
2009-01-18 20:53:59 +00:00
Daniel Veillard
09459bf107 add xmlMemDisplayLast to help debug incremental memory leaks, and some
* include/libxml/xmlmemory.h xmlmemory.c: add xmlMemDisplayLast to
  help debug incremental memory leaks, and some cleanups
* runxmlconf.c: use that new call and avoid ever touching the
  system catalog in the regression tests
Daniel

svn path=/trunk/; revision=3760
2008-07-30 12:58:11 +00:00
Daniel Veillard
2a512dac2d xmlFree(NULL) should not crash in debug mode should fix #491651 Daniel
* xmlmemory.c: xmlFree(NULL) should not crash in debug mode
  should fix #491651
Daniel

svn path=/trunk/; revision=3662
2007-10-30 20:24:40 +00:00
Daniel Veillard
f4721d66fc fix comment on versions do not spend too much time digging in dumped
* include/libxml/xmlversion.h.in: fix comment on versions
* xmlmemory.c: do not spend too much time digging in dumped memory
Daniel
2006-10-11 21:12:10 +00:00
Daniel Veillard
942d6c7b4f fixed #169630 segfault in xmlMemDisplay Daniel
* xmlmemory.c: fixed #169630 segfault in xmlMemDisplay
Daniel
2005-05-08 11:39:56 +00:00
Daniel Veillard
18ffe20c9e added the call to the breakpoint routine when a monitored block is
* xmlmemory.c: added the call to the breakpoint routine
  when a monitored block is reallocated or freed
Daniel
2005-04-14 17:50:59 +00:00
Daniel Veillard
5d4644ef6e revamped the elfgcchack.h format to cope with gcc4 change of aliasing
* doc/apibuild.py doc/elfgcchack.xsl: revamped the elfgcchack.h
  format to cope with gcc4 change of aliasing allowed scopes, had
  to add extra informations to doc/libxml2-api.xml to separate
  the header from the c module source.
* *.c: updated all c library files to add a #define bottom_xxx
  and reimport elfgcchack.h thereafter, and a bit of cleanups.
* doc//* testapi.c: regenerated when rebuilding the API
Daniel
2005-04-01 13:11:58 +00:00
Daniel Veillard
91b955c1af fixed ID deallocation problem based on patch from Steve Shepard fixes bug
* valid.c: fixed ID deallocation problem based on patch from
  Steve Shepard fixes bug #160893
* xmlmemory.c: improving comment.
* testapi.c: new test for xmlDictExists() is generated.
Daniel
2004-12-10 10:26:42 +00:00
Daniel Veillard
36e5cd5064 adding xmlMemBlocks() work on generator of an automatic API regression
* xmlmemory.c include/libxml/xmlmemory.h: adding xmlMemBlocks()
* Makefile.am gentest.py testapi.c: work on generator of an
  automatic API regression test tool.
* SAX2.c nanoftp.c parser.c parserInternals.c tree.c xmlIO.c
  xmlstring.c: various API hardeing changes as a result of running
  teh first set of automatic API regression tests.
* test/slashdot16.xml: apparently missing from CVS, commited it
Daniel
2004-11-02 14:52:23 +00:00
William M. Brack
13dfa87e91 added the routine xmlNanoHTTPContentLength to the external API
* nanohttp.c, include/libxml/nanohttp.h: added the routine
  xmlNanoHTTPContentLength to the external API (bug151968).
* parser.c: fixed unnecessary internal error message (bug152060);
  also changed call to strncmp over to xmlStrncmp.
* encoding.c: fixed compilation warning (bug152307).
* tree.c: fixed segfault in xmlCopyPropList (bug152368); fixed
  a couple of compilation warnings.
* HTMLtree.c, debugXML.c, xmlmemory.c: fixed a few compilation
  warnings; no change to logic.
2004-09-18 04:52:08 +00:00
Daniel Veillard
e15df587d6 applied a small fix from Steve Hay Daniel
* xmlmemory.c: applied a small fix from Steve Hay
Daniel
2004-07-13 15:25:08 +00:00
Daniel Veillard
529233ccdd some updates with memory debugging facilities while messing with libxslt
* xmlmemory.c python/libxml.c python/libxml2-python-api.xml:
  some updates with memory debugging facilities while messing
  with libxslt python bindings
Daniel
2004-07-02 12:23:44 +00:00
Daniel Veillard
f93a866079 applied patch from Stphane Bidoul to fix some Python bindings
* python/libxml.c python/generator.py python/libxml.py
  python/libxml2-python-api.xml python/libxml2class.txt:
  applied patch from Stphane Bidoul to fix some Python bindings
  initialization, then had to change the parserCleanup()
  to handle memory released there.
* xmlmemory.c: added more debugging comments.
Daniel
2004-07-01 12:56:30 +00:00
William M. Brack
5ab479b0e4 fixed problem when configuring using --with-thread-alloc
* configure.in, xmlmemory.c, globals.c: fixed problem when
  configuring using --with-thread-alloc
2004-06-10 13:00:15 +00:00
Aleksey Sanin
e9f0811a2f make xmlReallocLoc() accept NULL pointer 2004-01-22 22:20:31 +00:00
William M. Brack
9202942ba3 applied suggestion from Miloslav Trmac (see Bug 130419) and eliminated
* xmlmemory.c: applied suggestion from Miloslav Trmac (see
  Bug 130419) and eliminated xmlInitMemoryDone.  More
  improvement needed.

* xml2-config.in: added an additional flag (--exec-prefix) to
  allow library directory to be different from include directory
  (Bug 129558).
2004-01-04 01:01:14 +00:00
Daniel Veillard
1a9b7084f6 found and fixed a bug misallocating some non blank text node strings from
* SAX2.c: found and fixed a bug misallocating some non
  blank text node strings from the dictionnary.
* xmlmemory.c: fixed a problem with the memory debug mutex
  release.
Daniel
2004-01-02 10:42:01 +00:00
William M. Brack
72ee48d55f Fixed memory leak reported by Dave Beckett Removed spurious comment
* parser.c, xmlmemory.c, include/libxml/xmlmemory.h: Fixed
  memory leak reported by Dave Beckett
* xmlschemas.c: Removed spurious comment reported on the mailing
  list
* xinclude.c, xpath.c, xpointer.c, libxml/include/xpointer.h:
  Further work on Bug 129967 concerning xpointer range handling
  and range-to function; much better, but still not complete
2003-12-30 08:30:19 +00:00
William M. Brack
0622fe8b03 enhanced by adding mutex to protect global structures in a multi-threading
* xmlmemory.c: enhanced by adding mutex to protect global
  structures in a multi-threading environment.  This fixed
  some random errors on the Threads regression tests.

* encoding.c, include/libxml/encoding.h: Enhanced the handling of
  UTF-16, UTF-16LE and UTF-16BE encodings.  Now UTF-16 output is
  handled internally by default, with proper BOM and UTF-16LE
  encoding.  Native UTF-16LE and UTF-16BE encoding will not generate
  BOM on output, and will be automatically recognized on input.
* test/utf16lebom.xml, test/utf16bebom.xml, result/utf16?ebom*:
  added regression tests for above.
2003-11-29 10:47:56 +00:00