Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GNOME
libxml2
Commits
87076046
Commit
87076046
authored
May 03, 2004
by
Daniel Veillard
Browse files
adding a --maxmem option to check memory used. Daniel
* xmllint.c: adding a --maxmem option to check memory used. Daniel
parent
656ce948
Changes
2
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
87076046
Tue May 4 00:52:16 CEST 2004 Daniel Veillard <daniel@veillard.com>
* xmllint.c: adding a --maxmem option to check memory used.
Sat May 1 01:08:44 CEST 2004 Daniel Veillard <daniel@veillard.com>
* xmllint.c xmlsave.c python/generator.py python/libxml.c: Fixed
...
...
xmllint.c
View file @
87076046
...
...
@@ -102,6 +102,7 @@ static int shell = 0;
static
int
debugent
=
0
;
#endif
static
int
debug
=
0
;
static
int
maxmem
=
0
;
#ifdef LIBXML_TREE_ENABLED
static
int
copy
=
0
;
#endif
/* LIBXML_TREE_ENABLED */
...
...
@@ -170,10 +171,66 @@ static xmlPatternPtr patternc = NULL;
#endif
static
int
options
=
0
;
/*
* Internal timing routines to remove the necessity to have unix-specific
* function calls
*/
/************************************************************************
* *
* Memory allocation consumption debugging *
* *
************************************************************************/
static
void
OOM
(
void
)
{
fprintf
(
stderr
,
"Ran out of memory needs > %d bytes
\n
"
,
maxmem
);
progresult
=
9
;
}
static
void
myFreeFunc
(
void
*
mem
)
{
xmlMemFree
(
mem
);
}
static
void
*
myMallocFunc
(
size_t
size
)
{
void
*
ret
;
ret
=
xmlMemMalloc
(
size
);
if
(
ret
!=
NULL
)
{
if
(
xmlMemUsed
()
>
maxmem
)
{
OOM
();
xmlMemFree
(
ret
);
return
(
NULL
);
}
}
return
(
ret
);
}
static
void
*
myReallocFunc
(
void
*
mem
,
size_t
size
)
{
void
*
ret
;
ret
=
xmlMemRealloc
(
mem
,
size
);
if
(
ret
!=
NULL
)
{
if
(
xmlMemUsed
()
>
maxmem
)
{
OOM
();
xmlMemFree
(
ret
);
return
(
NULL
);
}
}
return
(
ret
);
}
static
char
*
myStrdupFunc
(
const
char
*
str
)
{
char
*
ret
;
ret
=
xmlMemoryStrdup
(
str
);
if
(
ret
!=
NULL
)
{
if
(
xmlMemUsed
()
>
maxmem
)
{
OOM
();
xmlFree
(
ret
);
return
(
NULL
);
}
}
return
(
ret
);
}
/************************************************************************
* *
* Internal timing routines to remove the necessity to have *
* unix-specific function calls. *
* *
************************************************************************/
#ifndef HAVE_GETTIMEOFDAY
#ifdef HAVE_SYS_TIMEB_H
...
...
@@ -1476,6 +1533,7 @@ static void usage(const char *name) {
#ifdef HAVE_SYS_MMAN_H
printf
(
"
\t
--memory : parse from memory
\n
"
);
#endif
printf
(
"
\t
--maxmem nbbytes : limits memory allocation to nbbytes bytes
\n
"
);
printf
(
"
\t
--nowarning : do not emit warnings from parser/validator
\n
"
);
printf
(
"
\t
--noblanks : drop (ignorable?) blanks spaces
\n
"
);
printf
(
"
\t
--nocdata : replace cdata section with text nodes
\n
"
);
...
...
@@ -1734,6 +1792,16 @@ main(int argc, char **argv) {
noblanks
++
;
xmlKeepBlanksDefault
(
0
);
}
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"
)))
{
noblanks
++
;
...
...
@@ -1943,6 +2011,11 @@ main(int argc, char **argv) {
i
++
;
continue
;
}
if
((
!
strcmp
(
argv
[
i
],
"-maxmem"
))
||
(
!
strcmp
(
argv
[
i
],
"--maxmem"
)))
{
i
++
;
continue
;
}
if
((
!
strcmp
(
argv
[
i
],
"-schema"
))
||
(
!
strcmp
(
argv
[
i
],
"--schema"
)))
{
i
++
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment