HEADER_DECLARE void Buffer_reserve(Buffer* buffer, size_t size){ if(!buffer->alloc_size && size){ buffer->ptr = system_alloc(size + 1); buffer->ptr[0] = 0; }else if(buffer->end > size){ return; }else if(!size){ buffer->ptr = "\0"; }else{ buffer->ptr = system_realloc(buffer->ptr, size + 1); } buffer->alloc_size = size; }
/* ** Resize the block of memory pointed to by p to n bytes. If the resize fails, set the mallocFailed flag in the connection object. */ void *systemCtxRealloc(appContext *db, void *p, int n) { void *pNew = 0; assert(db != 0); assert(system_mutex_held(db->mutex)); if (db->mallocFailed == 0) { if (p == 0) return systemCtxMallocRaw(db, n); if (isLookaside(db, p)) { if (n <= db->lookaside.sz) return p; pNew = systemCtxMallocRaw(db, n); if (pNew) { memcpy(pNew, p, db->lookaside.sz); systemCtxFree(db, p); } } else { assert(systemMemdebugHasType(p, MEMTYPE_DB)); assert(systemMemdebugHasType(p, MEMTYPE_LOOKASIDE|MEMTYPE_HEAP)); systemMemdebugSetType(p, MEMTYPE_HEAP); pNew = system_realloc(p, n); if (!pNew) { systemMemdebugSetType(p, MEMTYPE_DB|MEMTYPE_HEAP); db->mallocFailed = 1; } systemMemdebugSetType(pNew, MEMTYPE_DB | (db->lookaside.bEnabled ? MEMTYPE_LOOKASIDE : MEMTYPE_HEAP)); } } return pNew; }
gpointer intercept_realloc(gpointer ptr, gsize size) { return system_realloc(ptr, size); }
static am_status_t set_header(const char *key, const char *values, void **args) { Request *rq = (Request *)args[0]; pb_param *hdr_pp = pblock_find("full-headers", rq->reqpb); const char *the_key = key; if (hdr_pp != NULL) { if(values != NULL && *values != '\0') { //Added by bn152013 for 6739097 int append = 0; int length = strlen(the_key) + strlen(values) + 5; if (hdr_pp->value != NULL) { size_t len = strlen(hdr_pp->value); length += len; append = 1; hdr_pp->value = (char *) system_realloc(hdr_pp->value, length); hdr_pp->value[len] = '\0'; } else { hdr_pp->value = (char *) system_malloc(length); hdr_pp->value[0]='\0'; } if ( hdr_pp->value == NULL) { return (AM_NO_MEMORY); } if (append) strcat(hdr_pp->value, the_key); else strcpy(hdr_pp->value, the_key); strcat(hdr_pp->value, ": "); strcat(hdr_pp->value, values); strcat(hdr_pp->value, "\r\n"); } else { if(key[0] != '\0' && hdr_pp->value != NULL) { char *ptr = strstr(hdr_pp->value, the_key); if(ptr != NULL) { char *end_ptr = ptr + strlen(the_key); while(*end_ptr != '\r' && *end_ptr != '\n') ++end_ptr; end_ptr += 2; while(*end_ptr != '\0') { *ptr = *end_ptr; ptr += 1; end_ptr += 1; } *ptr = '\0'; } } } } if(values != NULL && *values != '\0') { //Added by bn152013 for 6739097 pblock_nvinsert(the_key, (char *)values, rq->headers); } else { param_free(pblock_remove(the_key, rq->headers)); } return (AM_SUCCESS); }