extern "C" void * MYCDECL CUSTOM_REALLOC (void * ptr, size_t sz) { if (ptr == NULL) { ptr = internalMalloc (sz); return ptr; } if (sz == 0) { CUSTOM_FREE (ptr); return NULL; } size_t objSize = CUSTOM_GETSIZE (ptr); void * buf = internalMalloc(sz); if (buf != NULL) { if (objSize == CUSTOM_GETSIZE(buf)) { // The objects are the same actual size. // Free the new object and return the original. CUSTOM_FREE (buf); return ptr; } // Copy the contents of the original object // up to the size of the new block. size_t minSize = (objSize < sz) ? objSize : sz; memcpy (buf, ptr, minSize); } // Free the old block. CUSTOM_FREE (ptr); // Return a pointer to the new one. return buf; }
// The wacky recalloc function, for Windows. extern "C" void * MYCDECL CUSTOM_RECALLOC (void * p, size_t num, size_t sz) { if (num * sz == 0) { CUSTOM_FREE (p); return NULL; } if (p == NULL) { return CUSTOM_CALLOC (num, sz); } CUSTOM_FREE (p); void * ptr = CUSTOM_CALLOC (num, sz); return ptr; }
void operator delete[] (void * ptr) #if defined(__APPLE__) throw () #endif { CUSTOM_FREE (ptr); }
void myfree (malloc_zone_t * zone, void * ptr) { if (zone == theZone) { CUSTOM_FREE(ptr); } else { originalFree (zone, ptr); } }
kii_socket_code_t socket_send_cb( kii_socket_context_t* socket_context, const char* buffer, size_t length) { int ret; context_t* ctx = (context_t*)socket_context->app_context; char* buff = CUSTOM_ALLOC(length); memcpy(buff, buffer, length); #if CONNECT_SSL ret = SSL_write(ctx->ssl, buff, length); #else ret = t_send(handle, ctx->sock, (uint_8 *)buff, length, 0); #endif CUSTOM_FREE(buff); if (ret > 0) { return KII_SOCKETC_OK; } else { printf("failed to send\n"); socket_close_cb(socket_context); return KII_SOCKETC_FAIL; } }
static void my_free_hook (void * ptr, const void *) { CUSTOM_FREE(ptr); }
void operator delete[] (void * ptr) { CUSTOM_FREE (ptr); }