[libxml2] Fix xmllint --maxmem
- From: Nick Wellnhofer <nwellnhof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libxml2] Fix xmllint --maxmem
- Date: Sun, 16 Jan 2022 18:06:14 +0000 (UTC)
commit 9f4cb84c620bf9a6b7c4880f027e28511349a975
Author: Nick Wellnhofer <wellnhofer aevum de>
Date: Sun Jan 16 18:39:51 2022 +0100
Fix xmllint --maxmem
xmlMemSetup must be called before initializing the parser, otherwise
some data structures will be allocated with system malloc instead of
our custom allocator. This throws off built-in memory debugging and
sanitizers.
xmllint.c | 27 +++++++++++++++++++++------
1 file changed, 21 insertions(+), 6 deletions(-)
---
diff --git a/xmllint.c b/xmllint.c
index a3fe10a2..2c7b9d04 100644
--- a/xmllint.c
+++ b/xmllint.c
@@ -3136,7 +3136,28 @@ main(int argc, char **argv) {
usage(stderr, argv[0]);
return(1);
}
+
+ /* xmlMemSetup must be called before initializing the parser. */
+ for (i = 1; i < argc ; i++) {
+ if (!strcmp(argv[i], "-"))
+ break;
+ if (argv[i][0] != '-')
+ continue;
+
+ if ((!strcmp(argv[i], "-maxmem")) ||
+ (!strcmp(argv[i], "--maxmem"))) {
+ i++;
+ if (sscanf(argv[i], "%d", &maxmem) == 1) {
+ xmlMemSetup(myFreeFunc, myMallocFunc, myReallocFunc,
+ myStrdupFunc);
+ } else {
+ maxmem = 0;
+ }
+ }
+ }
+
LIBXML_TEST_VERSION
+
for (i = 1; i < argc ; i++) {
if (!strcmp(argv[i], "-"))
break;
@@ -3382,12 +3403,6 @@ main(int argc, char **argv) {
else if ((!strcmp(argv[i], "-maxmem")) ||
(!strcmp(argv[i], "--maxmem"))) {
i++;
- if (sscanf(argv[i], "%d", &maxmem) == 1) {
- xmlMemSetup(myFreeFunc, myMallocFunc, myReallocFunc,
- myStrdupFunc);
- } else {
- maxmem = 0;
- }
}
else if ((!strcmp(argv[i], "-format")) ||
(!strcmp(argv[i], "--format"))) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]