* xmlMemoryStrdup: * @str: the initial string pointer * * a strdup() equivalent, with logging of the allocation info. * * Returns a pointer to the new string or NULL if allocation error occurred. */
| 255 | * Returns a pointer to the new string or NULL if allocation error occurred. |
| 256 | */ |
| 257 | char * |
| 258 | xmlMemoryStrdup(const char *str) { |
| 259 | char *s; |
| 260 | size_t size = strlen(str) + 1; |
| 261 | MEMHDR *p; |
| 262 | |
| 263 | xmlInitParser(); |
| 264 | |
| 265 | if (size > (MAX_SIZE_T - RESERVE_SIZE)) { |
| 266 | fprintf(stderr, "xmlMemoryStrdup: Unsigned overflow\n"); |
| 267 | return(NULL); |
| 268 | } |
| 269 | |
| 270 | p = (MEMHDR *) malloc(RESERVE_SIZE + size); |
| 271 | if (!p) { |
| 272 | fprintf(stderr, "xmlMemoryStrdup: Out of memory\n"); |
| 273 | return(NULL); |
| 274 | } |
| 275 | p->mh_tag = MEMTAG; |
| 276 | p->mh_size = size; |
| 277 | |
| 278 | xmlMutexLock(&xmlMemMutex); |
| 279 | debugMemSize += size; |
| 280 | debugMemBlocks++; |
| 281 | xmlMutexUnlock(&xmlMemMutex); |
| 282 | |
| 283 | s = (char *) HDR_2_CLIENT(p); |
| 284 | |
| 285 | memcpy(s, str, size); |
| 286 | |
| 287 | return(s); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * xmlMemSize: |
no test coverage detected