Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(347)

Side by Side Diff: third_party/libxml/src/xmlmemory.c

Issue 1193533007: Upgrade to libxml 2.9.2 and libxslt 1.1.28 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no iconv Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/libxml/src/xmllint.c ('k') | third_party/libxml/src/xmlmodule.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * xmlmemory.c: libxml memory allocator wrapper. 2 * xmlmemory.c: libxml memory allocator wrapper.
3 * 3 *
4 * daniel@veillard.com 4 * daniel@veillard.com
5 */ 5 */
6 6
7 #define IN_LIBXML 7 #define IN_LIBXML
8 #include "libxml.h" 8 #include "libxml.h"
9 9
10 #include <string.h> 10 #include <string.h>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 static int xmlMemInitialized = 0; 51 static int xmlMemInitialized = 0;
52 static unsigned long debugMemSize = 0; 52 static unsigned long debugMemSize = 0;
53 static unsigned long debugMemBlocks = 0; 53 static unsigned long debugMemBlocks = 0;
54 static unsigned long debugMaxMemSize = 0; 54 static unsigned long debugMaxMemSize = 0;
55 static xmlMutexPtr xmlMemMutex = NULL; 55 static xmlMutexPtr xmlMemMutex = NULL;
56 56
57 void xmlMallocBreakpoint(void); 57 void xmlMallocBreakpoint(void);
58 58
59 /************************************************************************ 59 /************************************************************************
60 * * 60 * *
61 * » » Macros, variables and associated types» » » * 61 *» » Macros, variables and associated types» » » *
62 * * 62 * *
63 ************************************************************************/ 63 ************************************************************************/
64 64
65 #if !defined(LIBXML_THREAD_ENABLED) && !defined(LIBXML_THREAD_ALLOC_ENABLED) 65 #if !defined(LIBXML_THREAD_ENABLED) && !defined(LIBXML_THREAD_ALLOC_ENABLED)
66 #ifdef xmlMalloc 66 #ifdef xmlMalloc
67 #undef xmlMalloc 67 #undef xmlMalloc
68 #endif 68 #endif
69 #ifdef xmlRealloc 69 #ifdef xmlRealloc
70 #undef xmlRealloc 70 #undef xmlRealloc
71 #endif 71 #endif
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 xmlGenericError(xmlGenericErrorContext, 198 xmlGenericError(xmlGenericErrorContext,
199 "Malloc(%d) Ok\n",size); 199 "Malloc(%d) Ok\n",size);
200 #endif 200 #endif
201 201
202 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint(); 202 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
203 203
204 ret = HDR_2_CLIENT(p); 204 ret = HDR_2_CLIENT(p);
205 205
206 if (xmlMemTraceBlockAt == ret) { 206 if (xmlMemTraceBlockAt == ret) {
207 xmlGenericError(xmlGenericErrorContext, 207 xmlGenericError(xmlGenericErrorContext,
208 » » » "%p : Malloc(%ld) Ok\n", xmlMemTraceBlockAt, size); 208 » » » "%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt,
209 » » » (long unsigned)size);
209 xmlMallocBreakpoint(); 210 xmlMallocBreakpoint();
210 } 211 }
211 212
212 TEST_POINT 213 TEST_POINT
213 214
214 return(ret); 215 return(ret);
215 } 216 }
216 217
217 /** 218 /**
218 * xmlMallocAtomicLoc: 219 * xmlMallocAtomicLoc:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 xmlGenericError(xmlGenericErrorContext, 267 xmlGenericError(xmlGenericErrorContext,
267 "Malloc(%d) Ok\n",size); 268 "Malloc(%d) Ok\n",size);
268 #endif 269 #endif
269 270
270 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint(); 271 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
271 272
272 ret = HDR_2_CLIENT(p); 273 ret = HDR_2_CLIENT(p);
273 274
274 if (xmlMemTraceBlockAt == ret) { 275 if (xmlMemTraceBlockAt == ret) {
275 xmlGenericError(xmlGenericErrorContext, 276 xmlGenericError(xmlGenericErrorContext,
276 » » » "%p : Malloc(%ld) Ok\n", xmlMemTraceBlockAt, size); 277 » » » "%p : Malloc(%lu) Ok\n", xmlMemTraceBlockAt,
278 » » » (long unsigned)size);
277 xmlMallocBreakpoint(); 279 xmlMallocBreakpoint();
278 } 280 }
279 281
280 TEST_POINT 282 TEST_POINT
281 283
282 return(ret); 284 return(ret);
283 } 285 }
284 /** 286 /**
285 * xmlMemMalloc: 287 * xmlMemMalloc:
286 * @size: an int specifying the size in byte to allocate. 288 * @size: an int specifying the size in byte to allocate.
(...skipping 17 matching lines...) Expand all
304 * @line: the line number 306 * @line: the line number
305 * 307 *
306 * a realloc() equivalent, with logging of the allocation info. 308 * a realloc() equivalent, with logging of the allocation info.
307 * 309 *
308 * Returns a pointer to the allocated area or NULL in case of lack of memory. 310 * Returns a pointer to the allocated area or NULL in case of lack of memory.
309 */ 311 */
310 312
311 void * 313 void *
312 xmlReallocLoc(void *ptr,size_t size, const char * file, int line) 314 xmlReallocLoc(void *ptr,size_t size, const char * file, int line)
313 { 315 {
314 MEMHDR *p; 316 MEMHDR *p, *tmp;
315 unsigned long number; 317 unsigned long number;
316 #ifdef DEBUG_MEMORY 318 #ifdef DEBUG_MEMORY
317 size_t oldsize; 319 size_t oldsize;
318 #endif 320 #endif
319 321
320 if (ptr == NULL) 322 if (ptr == NULL)
321 return(xmlMallocLoc(size, file, line)); 323 return(xmlMallocLoc(size, file, line));
322 324
323 if (!xmlMemInitialized) xmlInitMemory(); 325 if (!xmlMemInitialized) xmlInitMemory();
324 TEST_POINT 326 TEST_POINT
(...skipping 10 matching lines...) Expand all
335 debugMemSize -= p->mh_size; 337 debugMemSize -= p->mh_size;
336 debugMemBlocks--; 338 debugMemBlocks--;
337 #ifdef DEBUG_MEMORY 339 #ifdef DEBUG_MEMORY
338 oldsize = p->mh_size; 340 oldsize = p->mh_size;
339 #endif 341 #endif
340 #ifdef MEM_LIST 342 #ifdef MEM_LIST
341 debugmem_list_delete(p); 343 debugmem_list_delete(p);
342 #endif 344 #endif
343 xmlMutexUnlock(xmlMemMutex); 345 xmlMutexUnlock(xmlMemMutex);
344 346
345 p = (MEMHDR *) realloc(p,RESERVE_SIZE+size); 347 tmp = (MEMHDR *) realloc(p,RESERVE_SIZE+size);
346 if (!p) { 348 if (!tmp) {
349 » free(p);
347 goto error; 350 goto error;
348 } 351 }
352 p = tmp;
349 if (xmlMemTraceBlockAt == ptr) { 353 if (xmlMemTraceBlockAt == ptr) {
350 xmlGenericError(xmlGenericErrorContext, 354 xmlGenericError(xmlGenericErrorContext,
351 » » » "%p : Realloced(%ld -> %ld) Ok\n", 355 » » » "%p : Realloced(%lu -> %lu) Ok\n",
352 » » » xmlMemTraceBlockAt, p->mh_size, size); 356 » » » xmlMemTraceBlockAt, (long unsigned)p->mh_size,
357 » » » (long unsigned)size);
353 xmlMallocBreakpoint(); 358 xmlMallocBreakpoint();
354 } 359 }
355 p->mh_tag = MEMTAG; 360 p->mh_tag = MEMTAG;
356 p->mh_number = number; 361 p->mh_number = number;
357 p->mh_type = REALLOC_TYPE; 362 p->mh_type = REALLOC_TYPE;
358 p->mh_size = size; 363 p->mh_size = size;
359 p->mh_file = file; 364 p->mh_file = file;
360 p->mh_line = line; 365 p->mh_line = line;
361 xmlMutexLock(xmlMemMutex); 366 xmlMutexLock(xmlMemMutex);
362 debugMemSize += size; 367 debugMemSize += size;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize; 507 if (debugMemSize > debugMaxMemSize) debugMaxMemSize = debugMemSize;
503 #ifdef MEM_LIST 508 #ifdef MEM_LIST
504 debugmem_list_add(p); 509 debugmem_list_add(p);
505 #endif 510 #endif
506 xmlMutexUnlock(xmlMemMutex); 511 xmlMutexUnlock(xmlMemMutex);
507 512
508 s = (char *) HDR_2_CLIENT(p); 513 s = (char *) HDR_2_CLIENT(p);
509 514
510 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint(); 515 if (xmlMemStopAtBlock == p->mh_number) xmlMallocBreakpoint();
511 516
512 if (s != NULL) 517 strcpy(s,str);
513 strcpy(s,str);
514 else
515 goto error;
516 518
517 TEST_POINT 519 TEST_POINT
518 520
519 if (xmlMemTraceBlockAt == s) { 521 if (xmlMemTraceBlockAt == s) {
520 xmlGenericError(xmlGenericErrorContext, 522 xmlGenericError(xmlGenericErrorContext,
521 "%p : Strdup() Ok\n", xmlMemTraceBlockAt); 523 "%p : Strdup() Ok\n", xmlMemTraceBlockAt);
522 xmlMallocBreakpoint(); 524 xmlMallocBreakpoint();
523 } 525 }
524 526
525 return(s); 527 return(s);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 * xmlMemContentShow: 575 * xmlMemContentShow:
574 * @fp: a FILE descriptor used as the output file 576 * @fp: a FILE descriptor used as the output file
575 * @p: a memory block header 577 * @p: a memory block header
576 * 578 *
577 * tries to show some content from the memory block 579 * tries to show some content from the memory block
578 */ 580 */
579 581
580 static void 582 static void
581 xmlMemContentShow(FILE *fp, MEMHDR *p) 583 xmlMemContentShow(FILE *fp, MEMHDR *p)
582 { 584 {
583 int i,j,k,len = p->mh_size; 585 int i,j,k,len;
584 const char *buf = (const char *) HDR_2_CLIENT(p); 586 const char *buf;
585 587
586 if (p == NULL) { 588 if (p == NULL) {
587 fprintf(fp, " NULL"); 589 fprintf(fp, " NULL");
588 return; 590 return;
589 } 591 }
592 len = p->mh_size;
593 buf = (const char *) HDR_2_CLIENT(p);
590 594
591 for (i = 0;i < len;i++) { 595 for (i = 0;i < len;i++) {
592 if (buf[i] == 0) break; 596 if (buf[i] == 0) break;
593 if (!isprint((unsigned char) buf[i])) break; 597 if (!isprint((unsigned char) buf[i])) break;
594 } 598 }
595 if ((i < 4) && ((buf[i] != 0) || (i == 0))) { 599 if ((i < 4) && ((buf[i] != 0) || (i == 0))) {
596 if (len >= 4) { 600 if (len >= 4) {
597 MEMHDR *q; 601 MEMHDR *q;
598 void *cur; 602 void *cur;
599 603
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 if (freeFunc != NULL) *freeFunc = xmlFree; 1115 if (freeFunc != NULL) *freeFunc = xmlFree;
1112 if (mallocFunc != NULL) *mallocFunc = xmlMalloc; 1116 if (mallocFunc != NULL) *mallocFunc = xmlMalloc;
1113 if (mallocAtomicFunc != NULL) *mallocAtomicFunc = xmlMallocAtomic; 1117 if (mallocAtomicFunc != NULL) *mallocAtomicFunc = xmlMallocAtomic;
1114 if (reallocFunc != NULL) *reallocFunc = xmlRealloc; 1118 if (reallocFunc != NULL) *reallocFunc = xmlRealloc;
1115 if (strdupFunc != NULL) *strdupFunc = xmlMemStrdup; 1119 if (strdupFunc != NULL) *strdupFunc = xmlMemStrdup;
1116 return(0); 1120 return(0);
1117 } 1121 }
1118 1122
1119 #define bottom_xmlmemory 1123 #define bottom_xmlmemory
1120 #include "elfgcchack.h" 1124 #include "elfgcchack.h"
OLDNEW
« no previous file with comments | « third_party/libxml/src/xmllint.c ('k') | third_party/libxml/src/xmlmodule.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698