1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-10-23 01:52:48 +03:00

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.
This commit is contained in:
Nick Wellnhofer
2023-12-18 21:32:49 +01:00
parent bc1e030664
commit ecb4c9fb28
8 changed files with 60 additions and 130 deletions

View File

@@ -11,6 +11,7 @@
#include "libxml.h" #include "libxml.h"
#ifdef LIBXML_LEGACY_ENABLED #ifdef LIBXML_LEGACY_ENABLED
#include <stdio.h>
#include <string.h> #include <string.h>
#include <libxml/tree.h> #include <libxml/tree.h>
@@ -55,7 +56,7 @@ htmlDecodeEntities(htmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"htmlDecodeEntities() deprecated function reached\n"); "htmlDecodeEntities() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -416,7 +417,7 @@ xmlDecodeEntities(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlDecodeEntities() deprecated function reached\n"); "xmlDecodeEntities() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -446,7 +447,7 @@ xmlNamespaceParseNCName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlNamespaceParseNCName() deprecated function reached\n"); "xmlNamespaceParseNCName() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -481,7 +482,7 @@ xmlNamespaceParseQName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlNamespaceParseQName() deprecated function reached\n"); "xmlNamespaceParseQName() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -510,7 +511,7 @@ xmlNamespaceParseNSDef(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlNamespaceParseNSDef() deprecated function reached\n"); "xmlNamespaceParseNSDef() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -533,7 +534,7 @@ xmlParseQuotedString(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlParseQuotedString() deprecated function reached\n"); "xmlParseQuotedString() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -561,7 +562,7 @@ xmlParseNamespace(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlParseNamespace() deprecated function reached\n"); "xmlParseNamespace() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -593,7 +594,7 @@ xmlScanName(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlScanName() deprecated function reached\n"); "xmlScanName() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -633,7 +634,7 @@ xmlParserHandleReference(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED)
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlParserHandleReference() deprecated function reached\n"); "xmlParserHandleReference() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -659,7 +660,7 @@ xmlHandleEntity(xmlParserCtxtPtr ctxt ATTRIBUTE_UNUSED,
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlHandleEntity() deprecated function reached\n"); "xmlHandleEntity() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -683,7 +684,7 @@ xmlNewGlobalNs(xmlDocPtr doc ATTRIBUTE_UNUSED,
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlNewGlobalNs() deprecated function reached\n"); "xmlNewGlobalNs() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -703,7 +704,7 @@ xmlUpgradeOldNs(xmlDocPtr doc ATTRIBUTE_UNUSED)
static int deprecated = 0; static int deprecated = 0;
if (!deprecated) { if (!deprecated) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlUpgradeOldNs() deprecated function reached\n"); "xmlUpgradeOldNs() deprecated function reached\n");
deprecated = 1; deprecated = 1;
} }
@@ -729,9 +730,9 @@ xmlEncodeEntities(xmlDocPtr doc ATTRIBUTE_UNUSED,
static int warning = 1; static int warning = 1;
if (warning) { if (warning) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"Deprecated API xmlEncodeEntities() used\n"); "Deprecated API xmlEncodeEntities() used\n");
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
" change code to use xmlEncodeEntitiesReentrant()\n"); " change code to use xmlEncodeEntitiesReentrant()\n");
warning = 0; warning = 0;
} }
@@ -747,7 +748,7 @@ static int deprecated_v1_msg = 0;
#define DEPRECATED(n) \ #define DEPRECATED(n) \
if (deprecated_v1_msg == 0) \ if (deprecated_v1_msg == 0) \
xmlGenericError(xmlGenericErrorContext, \ fprintf(stderr, \
"Use of deprecated SAXv1 function %s\n", n); \ "Use of deprecated SAXv1 function %s\n", n); \
deprecated_v1_msg++; deprecated_v1_msg++;

27
list.c
View File

@@ -188,18 +188,13 @@ xmlListPtr
xmlListCreate(xmlListDeallocator deallocator, xmlListDataCompare compare) xmlListCreate(xmlListDeallocator deallocator, xmlListDataCompare compare)
{ {
xmlListPtr l; xmlListPtr l;
if (NULL == (l = (xmlListPtr )xmlMalloc( sizeof(xmlList)))) { if (NULL == (l = (xmlListPtr )xmlMalloc( sizeof(xmlList))))
xmlGenericError(xmlGenericErrorContext,
"Cannot initialize memory for list");
return (NULL); return (NULL);
}
/* Initialize the list to NULL */ /* Initialize the list to NULL */
memset(l, 0, sizeof(xmlList)); memset(l, 0, sizeof(xmlList));
/* Add the sentinel */ /* Add the sentinel */
if (NULL ==(l->sentinel = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) { if (NULL ==(l->sentinel = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) {
xmlGenericError(xmlGenericErrorContext,
"Cannot initialize memory for sentinel");
xmlFree(l); xmlFree(l);
return (NULL); return (NULL);
} }
@@ -279,11 +274,8 @@ xmlListInsert(xmlListPtr l, void *data)
lkPlace = xmlListLowerSearch(l, data); lkPlace = xmlListLowerSearch(l, data);
/* Add the new link */ /* Add the new link */
lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink)); lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink));
if (lkNew == NULL) { if (lkNew == NULL)
xmlGenericError(xmlGenericErrorContext,
"Cannot initialize memory for new link");
return (1); return (1);
}
lkNew->data = data; lkNew->data = data;
lkPlace = lkPlace->prev; lkPlace = lkPlace->prev;
lkNew->next = lkPlace->next; lkNew->next = lkPlace->next;
@@ -311,11 +303,8 @@ int xmlListAppend(xmlListPtr l, void *data)
lkPlace = xmlListHigherSearch(l, data); lkPlace = xmlListHigherSearch(l, data);
/* Add the new link */ /* Add the new link */
lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink)); lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink));
if (lkNew == NULL) { if (lkNew == NULL)
xmlGenericError(xmlGenericErrorContext,
"Cannot initialize memory for new link");
return (1); return (1);
}
lkNew->data = data; lkNew->data = data;
lkNew->next = lkPlace->next; lkNew->next = lkPlace->next;
(lkPlace->next)->prev = lkNew; (lkPlace->next)->prev = lkNew;
@@ -548,11 +537,8 @@ xmlListPushFront(xmlListPtr l, void *data)
lkPlace = l->sentinel; lkPlace = l->sentinel;
/* Add the new link */ /* Add the new link */
lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink)); lkNew = (xmlLinkPtr) xmlMalloc(sizeof(xmlLink));
if (lkNew == NULL) { if (lkNew == NULL)
xmlGenericError(xmlGenericErrorContext,
"Cannot initialize memory for new link");
return (0); return (0);
}
lkNew->data = data; lkNew->data = data;
lkNew->next = lkPlace->next; lkNew->next = lkPlace->next;
(lkPlace->next)->prev = lkNew; (lkPlace->next)->prev = lkNew;
@@ -579,11 +565,8 @@ xmlListPushBack(xmlListPtr l, void *data)
return(0); return(0);
lkPlace = l->sentinel->prev; lkPlace = l->sentinel->prev;
/* Add the new link */ /* Add the new link */
if (NULL ==(lkNew = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink)))) { if (NULL ==(lkNew = (xmlLinkPtr )xmlMalloc(sizeof(xmlLink))))
xmlGenericError(xmlGenericErrorContext,
"Cannot initialize memory for new link");
return (0); return (0);
}
lkNew->data = data; lkNew->data = data;
lkNew->next = lkPlace->next; lkNew->next = lkPlace->next;
(lkPlace->next)->prev = lkNew; (lkPlace->next)->prev = lkNew;

View File

@@ -137,9 +137,9 @@ int have_ipv6(void) {
* Handle an out of memory condition * Handle an out of memory condition
*/ */
static void static void
xmlFTPErrMemory(const char *extra) xmlFTPErrMemory(const char *extra ATTRIBUTE_UNUSED)
{ {
__xmlSimpleError(XML_FROM_FTP, XML_ERR_NO_MEMORY, NULL, NULL, extra); xmlRaiseMemoryError(NULL, NULL, NULL, XML_FROM_FTP, NULL);
} }
/** /**
@@ -1923,7 +1923,7 @@ static
void ftpList(void *userData, const char *filename, const char* attrib, void ftpList(void *userData, const char *filename, const char* attrib,
const char *owner, const char *group, unsigned long size, int links, const char *owner, const char *group, unsigned long size, int links,
int year, const char *month, int day, int hour, int minute) { int year, const char *month, int day, int hour, int minute) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"%s %s %s %ld %s\n", attrib, owner, group, size, filename); "%s %s %s %ld %s\n", attrib, owner, group, size, filename);
} }
static static
@@ -1945,7 +1945,7 @@ int main(int argc, char **argv) {
if (argc > 1) { if (argc > 1) {
ctxt = xmlNanoFTPNewCtxt(argv[1]); ctxt = xmlNanoFTPNewCtxt(argv[1]);
if (xmlNanoFTPConnect(ctxt) < 0) { if (xmlNanoFTPConnect(ctxt) < 0) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"Couldn't connect to %s\n", argv[1]); "Couldn't connect to %s\n", argv[1]);
exit(1); exit(1);
} }
@@ -1954,7 +1954,7 @@ int main(int argc, char **argv) {
} else } else
ctxt = xmlNanoFTPConnectTo("localhost", 0); ctxt = xmlNanoFTPConnectTo("localhost", 0);
if (ctxt == NULL) { if (ctxt == NULL) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"Couldn't connect to localhost\n"); "Couldn't connect to localhost\n");
exit(1); exit(1);
} }
@@ -1962,7 +1962,7 @@ int main(int argc, char **argv) {
output = fopen("/tmp/tstdata", "w"); output = fopen("/tmp/tstdata", "w");
if (output != NULL) { if (output != NULL) {
if (xmlNanoFTPGet(ctxt, ftpData, (void *) output, tstfile) < 0) if (xmlNanoFTPGet(ctxt, ftpData, (void *) output, tstfile) < 0)
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"Failed to get file\n"); "Failed to get file\n");
} }
@@ -1974,7 +1974,7 @@ int main(int argc, char **argv) {
#ifdef STANDALONE #ifdef STANDALONE
#include <stdio.h> #include <stdio.h>
int main(int argc, char **argv) { int main(int argc, char **argv) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"%s : FTP support not compiled in\n", argv[0]); "%s : FTP support not compiled in\n", argv[0]);
return(0); return(0);
} }

View File

@@ -147,9 +147,9 @@ static int xmlNanoHTTPFetchContent( void * ctx, char ** ptr, int * len );
* Handle an out of memory condition * Handle an out of memory condition
*/ */
static void static void
xmlHTTPErrMemory(const char *extra) xmlHTTPErrMemory(void)
{ {
__xmlSimpleError(XML_FROM_HTTP, XML_ERR_NO_MEMORY, NULL, NULL, extra); xmlRaiseMemoryError(NULL, NULL, NULL, XML_FROM_HTTP, NULL);
} }
/** /**
@@ -358,7 +358,7 @@ xmlNanoHTTPNewCtxt(const char *URL) {
ret = (xmlNanoHTTPCtxtPtr) xmlMalloc(sizeof(xmlNanoHTTPCtxt)); ret = (xmlNanoHTTPCtxtPtr) xmlMalloc(sizeof(xmlNanoHTTPCtxt));
if (ret == NULL) { if (ret == NULL) {
xmlHTTPErrMemory("allocating context"); xmlHTTPErrMemory();
return(NULL); return(NULL);
} }
@@ -504,7 +504,7 @@ xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt)
if (ctxt->in == NULL) { if (ctxt->in == NULL) {
ctxt->in = (char *) xmlMallocAtomic(65000); ctxt->in = (char *) xmlMallocAtomic(65000);
if (ctxt->in == NULL) { if (ctxt->in == NULL) {
xmlHTTPErrMemory("allocating input"); xmlHTTPErrMemory();
ctxt->last = -1; ctxt->last = -1;
return (-1); return (-1);
} }
@@ -529,7 +529,7 @@ xmlNanoHTTPRecv(xmlNanoHTTPCtxtPtr ctxt)
ctxt->inlen *= 2; ctxt->inlen *= 2;
ctxt->in = (char *) xmlRealloc(tmp_ptr, ctxt->inlen); ctxt->in = (char *) xmlRealloc(tmp_ptr, ctxt->inlen);
if (ctxt->in == NULL) { if (ctxt->in == NULL) {
xmlHTTPErrMemory("allocating input buffer"); xmlHTTPErrMemory();
xmlFree(tmp_ptr); xmlFree(tmp_ptr);
ctxt->last = -1; ctxt->last = -1;
return (-1); return (-1);
@@ -1444,7 +1444,7 @@ retry:
bp = (char*)xmlMallocAtomic(blen); bp = (char*)xmlMallocAtomic(blen);
if ( bp == NULL ) { if ( bp == NULL ) {
xmlNanoHTTPFreeCtxt( ctxt ); xmlNanoHTTPFreeCtxt( ctxt );
xmlHTTPErrMemory("allocating header buffer"); xmlHTTPErrMemory();
return ( NULL ); return ( NULL );
} }
@@ -1831,9 +1831,9 @@ int main(int argc, char **argv) {
xmlNanoHTTPFetch(argv[1], "-", &contentType); xmlNanoHTTPFetch(argv[1], "-", &contentType);
if (contentType != NULL) xmlFree(contentType); if (contentType != NULL) xmlFree(contentType);
} else { } else {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"%s: minimal HTTP GET implementation\n", argv[0]); "%s: minimal HTTP GET implementation\n", argv[0]);
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"\tusage %s [ URL [ filename ] ]\n", argv[0]); "\tusage %s [ URL [ filename ] ]\n", argv[0]);
} }
xmlNanoHTTPCleanup(); xmlNanoHTTPCleanup();
@@ -1844,7 +1844,7 @@ int main(int argc, char **argv) {
#ifdef STANDALONE #ifdef STANDALONE
#include <stdio.h> #include <stdio.h>
int main(int argc, char **argv) { int main(int argc, char **argv) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"%s : HTTP support not compiled in\n", argv[0]); "%s : HTTP support not compiled in\n", argv[0]);
return(0); return(0);
} }

View File

@@ -697,10 +697,6 @@ rollback:
* * * *
************************************************************************/ ************************************************************************/
#define TODO \
xmlGenericError(xmlGenericErrorContext, \
"Unimplemented block at %s:%d\n", \
__FILE__, __LINE__);
#define CUR (*ctxt->cur) #define CUR (*ctxt->cur)
#define SKIP(val) ctxt->cur += (val) #define SKIP(val) ctxt->cur += (val)
#define NXT(val) ctxt->cur[(val)] #define NXT(val) ctxt->cur[(val)]

View File

@@ -498,9 +498,8 @@ xmlGlobalInitMutexLock(void) {
if (global_init_lock == NULL) { if (global_init_lock == NULL) {
cs = malloc(sizeof(CRITICAL_SECTION)); cs = malloc(sizeof(CRITICAL_SECTION));
if (cs == NULL) { if (cs == NULL) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr, "libxml2: xmlInitParser: out of memory\n");
"xmlGlobalInitMutexLock: out of memory\n"); abort();
return;
} }
InitializeCriticalSection(cs); InitializeCriticalSection(cs);

View File

@@ -126,7 +126,7 @@ static void debugmem_list_delete(MEMHDR *);
void void
xmlMallocBreakpoint(void) { xmlMallocBreakpoint(void) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlMallocBreakpoint reached on block %d\n", xmlMemStopAtBlock); "xmlMallocBreakpoint reached on block %d\n", xmlMemStopAtBlock);
} }
@@ -152,7 +152,7 @@ xmlMallocLoc(size_t size, const char * file, int line)
TEST_POINT TEST_POINT
if (size > (MAX_SIZE_T - RESERVE_SIZE)) { if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlMallocLoc : Unsigned overflow\n"); "xmlMallocLoc : Unsigned overflow\n");
return(NULL); return(NULL);
} }
@@ -160,7 +160,7 @@ xmlMallocLoc(size_t size, const char * file, int line)
p = (MEMHDR *) malloc(RESERVE_SIZE+size); p = (MEMHDR *) malloc(RESERVE_SIZE+size);
if (!p) { if (!p) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlMallocLoc : Out of free space\n"); "xmlMallocLoc : Out of free space\n");
return(NULL); return(NULL);
} }
@@ -184,7 +184,7 @@ xmlMallocLoc(size_t size, const char * file, int line)
ret = HDR_2_CLIENT(p); ret = HDR_2_CLIENT(p);
if (xmlMemTraceBlockAt == ret) { if (xmlMemTraceBlockAt == ret) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt, "%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt,
(long unsigned)size); (long unsigned)size);
xmlMallocBreakpoint(); xmlMallocBreakpoint();
@@ -217,7 +217,7 @@ xmlMallocAtomicLoc(size_t size, const char * file, int line)
TEST_POINT TEST_POINT
if (size > (MAX_SIZE_T - RESERVE_SIZE)) { if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlMallocAtomicLoc : Unsigned overflow\n"); "xmlMallocAtomicLoc : Unsigned overflow\n");
return(NULL); return(NULL);
} }
@@ -225,7 +225,7 @@ xmlMallocAtomicLoc(size_t size, const char * file, int line)
p = (MEMHDR *) malloc(RESERVE_SIZE+size); p = (MEMHDR *) malloc(RESERVE_SIZE+size);
if (!p) { if (!p) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlMallocAtomicLoc : Out of free space\n"); "xmlMallocAtomicLoc : Out of free space\n");
return(NULL); return(NULL);
} }
@@ -249,7 +249,7 @@ xmlMallocAtomicLoc(size_t size, const char * file, int line)
ret = HDR_2_CLIENT(p); ret = HDR_2_CLIENT(p);
if (xmlMemTraceBlockAt == ret) { if (xmlMemTraceBlockAt == ret) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt, "%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt,
(long unsigned)size); (long unsigned)size);
xmlMallocBreakpoint(); xmlMallocBreakpoint();
@@ -315,7 +315,7 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
xmlMutexUnlock(&xmlMemMutex); xmlMutexUnlock(&xmlMemMutex);
if (size > (MAX_SIZE_T - RESERVE_SIZE)) { if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlReallocLoc : Unsigned overflow\n"); "xmlReallocLoc : Unsigned overflow\n");
return(NULL); return(NULL);
} }
@@ -327,7 +327,7 @@ xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
} }
p = tmp; p = tmp;
if (xmlMemTraceBlockAt == ptr) { if (xmlMemTraceBlockAt == ptr) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"%p : Realloced(%lu -> %lu) Ok\n", "%p : Realloced(%lu -> %lu) Ok\n",
xmlMemTraceBlockAt, (long unsigned)p->mh_size, xmlMemTraceBlockAt, (long unsigned)p->mh_size,
(long unsigned)size); (long unsigned)size);
@@ -387,13 +387,13 @@ xmlMemFree(void *ptr)
return; return;
if (ptr == (void *) -1) { if (ptr == (void *) -1) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"trying to free pointer from freed area\n"); "trying to free pointer from freed area\n");
goto error; goto error;
} }
if (xmlMemTraceBlockAt == ptr) { if (xmlMemTraceBlockAt == ptr) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"%p : Freed()\n", xmlMemTraceBlockAt); "%p : Freed()\n", xmlMemTraceBlockAt);
xmlMallocBreakpoint(); xmlMallocBreakpoint();
} }
@@ -425,7 +425,7 @@ xmlMemFree(void *ptr)
return; return;
error: error:
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlMemFree(%p) error\n", ptr); "xmlMemFree(%p) error\n", ptr);
xmlMallocBreakpoint(); xmlMallocBreakpoint();
return; return;
@@ -453,7 +453,7 @@ xmlMemStrdupLoc(const char *str, const char *file, int line)
TEST_POINT TEST_POINT
if (size > (MAX_SIZE_T - RESERVE_SIZE)) { if (size > (MAX_SIZE_T - RESERVE_SIZE)) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"xmlMemStrdupLoc : Unsigned overflow\n"); "xmlMemStrdupLoc : Unsigned overflow\n");
return(NULL); return(NULL);
} }
@@ -486,7 +486,7 @@ xmlMemStrdupLoc(const char *str, const char *file, int line)
TEST_POINT TEST_POINT
if (xmlMemTraceBlockAt == s) { if (xmlMemTraceBlockAt == s) {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"%p : Strdup() Ok\n", xmlMemTraceBlockAt); "%p : Strdup() Ok\n", xmlMemTraceBlockAt);
xmlMallocBreakpoint(); xmlMallocBreakpoint();
} }
@@ -733,7 +733,7 @@ static void debugmem_list_delete(MEMHDR *p)
static void debugmem_tag_error(void *p) static void debugmem_tag_error(void *p)
{ {
xmlGenericError(xmlGenericErrorContext, fprintf(stderr,
"Memory tag error occurs :%p \n\t bye\n", p); "Memory tag error occurs :%p \n\t bye\n", p);
#ifdef MEM_LIST #ifdef MEM_LIST
if (stderr) if (stderr)

View File

@@ -41,27 +41,6 @@ static int xmlModulePlatformSymbol(void *handle, const char *name, void **result
* * * *
************************************************************************/ ************************************************************************/
/**
* xmlModuleErrMemory:
* @extra: extra information
*
* Handle an out of memory condition
*/
static void
xmlModuleErrMemory(xmlModulePtr module, const char *extra)
{
const char *name = NULL;
if (module != NULL) {
name = (const char *) module->name;
}
__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
XML_ERR_NO_MEMORY, XML_ERR_FATAL, NULL, 0, extra,
name, NULL, 0, 0,
"Memory allocation failed : %s\n", extra);
}
/** /**
* xmlModuleOpen: * xmlModuleOpen:
* @name: the module name * @name: the module name
@@ -82,10 +61,8 @@ xmlModuleOpen(const char *name, int options ATTRIBUTE_UNUSED)
xmlModulePtr module; xmlModulePtr module;
module = (xmlModulePtr) xmlMalloc(sizeof(xmlModule)); module = (xmlModulePtr) xmlMalloc(sizeof(xmlModule));
if (module == NULL) { if (module == NULL)
xmlModuleErrMemory(NULL, "creating module");
return (NULL); return (NULL);
}
memset(module, 0, sizeof(xmlModule)); memset(module, 0, sizeof(xmlModule));
@@ -93,9 +70,6 @@ xmlModuleOpen(const char *name, int options ATTRIBUTE_UNUSED)
if (module->handle == NULL) { if (module->handle == NULL) {
xmlFree(module); xmlFree(module);
__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0,
name, NULL, 0, 0, "failed to open %s\n", name);
return(NULL); return(NULL);
} }
@@ -122,23 +96,13 @@ xmlModuleSymbol(xmlModulePtr module, const char *name, void **symbol)
{ {
int rc = -1; int rc = -1;
if ((NULL == module) || (symbol == NULL) || (name == NULL)) { if ((NULL == module) || (symbol == NULL) || (name == NULL))
__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0,
NULL, NULL, 0, 0, "null parameter\n");
return rc; return rc;
}
rc = xmlModulePlatformSymbol(module->handle, name, symbol); rc = xmlModulePlatformSymbol(module->handle, name, symbol);
if (rc == -1) { if (rc == -1)
__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
XML_MODULE_OPEN, XML_ERR_FATAL, NULL, 0, 0,
name, NULL, 0, 0,
"failed to find symbol: %s\n",
(name == NULL ? "NULL" : name));
return rc; return rc;
}
return rc; return rc;
} }
@@ -158,22 +122,13 @@ xmlModuleClose(xmlModulePtr module)
{ {
int rc; int rc;
if (NULL == module) { if (NULL == module)
__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0,
NULL, NULL, 0, 0, "null module pointer\n");
return -1; return -1;
}
rc = xmlModulePlatformClose(module->handle); rc = xmlModulePlatformClose(module->handle);
if (rc != 0) { if (rc != 0)
__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, 0,
(const char *) module->name, NULL, 0, 0,
"failed to close: %s\n", module->name);
return -2; return -2;
}
rc = xmlModuleFree(module); rc = xmlModuleFree(module);
return (rc); return (rc);
@@ -192,12 +147,8 @@ xmlModuleClose(xmlModulePtr module)
int int
xmlModuleFree(xmlModulePtr module) xmlModuleFree(xmlModulePtr module)
{ {
if (NULL == module) { if (NULL == module)
__xmlRaiseError(NULL, NULL, NULL, NULL, NULL, XML_FROM_MODULE,
XML_MODULE_CLOSE, XML_ERR_FATAL, NULL, 0, NULL,
NULL, NULL, 0, 0, "null module pointer\n");
return -1; return -1;
}
xmlFree(module->name); xmlFree(module->name);
xmlFree(module); xmlFree(module);