bool Container::Refit() { #ifdef CONTAINER_STATS // Subtract previous amount of bytes mUsedRam-=mMaxNbEntries*sizeof(TUInt32); #endif // Get just enough entries mMaxNbEntries = mCurNbEntries; if(!mMaxNbEntries) { return false; } // Get just enough bytes TUInt32* NewEntries = new TUInt32[mMaxNbEntries]; CHECKALLOC(NewEntries); #ifdef CONTAINER_STATS // Add current amount of bytes mUsedRam+=mMaxNbEntries*sizeof(TUInt32); #endif // Copy old data CopyMemory(NewEntries, mEntries, mCurNbEntries*sizeof(TUInt32)); // Delete old data DELETEARRAY(mEntries); // Assign new pointer mEntries = NewEntries; return true; }
/** * Push a key to the key list. * */ key_type* keylist_push(keylist_type* kl, const char* locator, const char* resourcerecord, uint8_t algorithm, uint32_t flags, int publish, int ksk, int zsk) { key_type* keys_old = NULL; ods_log_assert(kl); keys_old = kl->keys; CHECKALLOC(kl->keys = (key_type*) malloc((kl->count + 1) * sizeof(key_type))); if (!kl->keys) { ods_fatal_exit("[%s] unable to add key: allocator_alloc() failed", key_str); } if (keys_old) { memcpy(kl->keys, keys_old, (kl->count) * sizeof(key_type)); } free(keys_old); kl->count++; kl->keys[kl->count -1].locator = locator; kl->keys[kl->count -1].resourcerecord = resourcerecord; kl->keys[kl->count -1].algorithm = algorithm; kl->keys[kl->count -1].flags = flags; kl->keys[kl->count -1].publish = publish; kl->keys[kl->count -1].ksk = ksk; kl->keys[kl->count -1].zsk = zsk; kl->keys[kl->count -1].dnskey = NULL; kl->keys[kl->count -1].params = NULL; return &kl->keys[kl->count -1]; }
bool RadixSort::Resize(udword nb) { // Free previously used ram DELETEARRAY(mIndices2); DELETEARRAY(mIndices); // Get some fresh one mIndices = new udword[nb]; CHECKALLOC(mIndices); mIndices2 = new udword[nb]; CHECKALLOC(mIndices2); mCurrentSize = nb; // Initialize indices so that the input buffer is read in sequential order ResetIndices(); return true; }
static void engine_create_drudgers(engine_type* engine) { size_t i = 0; ods_log_assert(engine); ods_log_assert(engine->config); CHECKALLOC(engine->drudgers = (worker_type**) malloc(((size_t)engine->config->num_signer_threads) * sizeof(worker_type*))); for (i=0; i < (size_t) engine->config->num_signer_threads; i++) { engine->drudgers[i] = worker_create(i, WORKER_DRUDGER); } }
/** * Create zone transfer handler. * */ xfrhandler_type* xfrhandler_create() { xfrhandler_type* xfrh = NULL; CHECKALLOC(xfrh = (xfrhandler_type*) malloc(sizeof(xfrhandler_type))); xfrh->engine = NULL; xfrh->packet = NULL; xfrh->netio = NULL; xfrh->tcp_set = NULL; xfrh->tcp_waiting_first = NULL; xfrh->udp_waiting_first = NULL; xfrh->udp_waiting_last = NULL; xfrh->udp_use_num = 0; xfrh->start_time = 0; xfrh->current_time = 0; xfrh->got_time = 0; xfrh->need_to_exit = 0; xfrh->started = 0; /* notify */ xfrh->notify_waiting_first = NULL; xfrh->notify_waiting_last = NULL; xfrh->notify_udp_num = 0; /* setup */ xfrh->netio = netio_create(); if (!xfrh->netio) { ods_log_error("[%s] unable to create xfrhandler: " "netio_create() failed", xfrh_str); xfrhandler_cleanup(xfrh); return NULL; } xfrh->packet = buffer_create(PACKET_BUFFER_SIZE); if (!xfrh->packet) { ods_log_error("[%s] unable to create xfrhandler: " "buffer_create() failed", xfrh_str); xfrhandler_cleanup(xfrh); return NULL; } xfrh->tcp_set = tcp_set_create(); if (!xfrh->tcp_set) { ods_log_error("[%s] unable to create xfrhandler: " "tcp_set_create() failed", xfrh_str); xfrhandler_cleanup(xfrh); return NULL; } xfrh->dnshandler.fd = -1; xfrh->dnshandler.user_data = (void*) xfrh; xfrh->dnshandler.timeout = 0; xfrh->dnshandler.event_types = NETIO_EVENT_READ; xfrh->dnshandler.event_handler = xfrhandler_handle_dns; xfrh->dnshandler.free_handler = 0; return xfrh; }
void expand_table(void **table, int oldsize, int newsize) { if (newsize > oldsize) { int *temp; temp = (int *) Malloc(newsize); /* allocate a new table */ CHECKALLOC(temp, "vinum: Can't expand table\n"); bzero((char *) temp, newsize); /* clean it all out */ if (*table != NULL) { /* already something there, */ bcopy((char *) *table, (char *) temp, oldsize); /* copy it to the old table */ Free(*table); } *table = temp; } }
/** * Create a new key list. * */ keylist_type* keylist_create(signconf_type* signconf) { keylist_type* kl = NULL; if (!signconf) { return NULL; } CHECKALLOC(kl = (keylist_type*) malloc((sizeof(keylist_type)))); if (!kl) { ods_log_error("[%s] create list failed: allocator_alloc() failed", key_str); return NULL; } kl->sc = signconf; kl->count = 0; kl->keys = NULL; return kl; }
/** * Create engine. * */ static engine_type* engine_create(void) { engine_type* engine; CHECKALLOC(engine = (engine_type*) malloc(sizeof(engine_type))); engine->config = NULL; engine->workers = NULL; engine->drudgers = NULL; engine->cmdhandler = NULL; engine->cmdhandler_done = 0; engine->dnshandler = NULL; engine->xfrhandler = NULL; engine->taskq = NULL; engine->signq = NULL; engine->pid = -1; engine->uid = -1; engine->gid = -1; engine->daemonize = 0; engine->need_to_exit = 0; engine->need_to_reload = 0; lock_basic_init(&engine->signal_lock); lock_basic_set(&engine->signal_cond); lock_basic_lock(&engine->signal_lock); engine->signal = SIGNAL_INIT; lock_basic_unlock(&engine->signal_lock); engine->zonelist = zonelist_create(); if (!engine->zonelist) { engine_cleanup(engine); return NULL; } engine->taskq = schedule_create(); if (!engine->taskq) { engine_cleanup(engine); return NULL; } engine->signq = fifoq_create(); if (!engine->signq) { engine_cleanup(engine); return NULL; } return engine; }
bool Container::Resize(TUInt32 needed) { #ifdef CONTAINER_STATS // Subtract previous amount of bytes mUsedRam -= mMaxNbEntries*sizeof(TUInt32); #endif // Get more entries mMaxNbEntries = mMaxNbEntries ? TUInt32(float(mMaxNbEntries)*mGrowthFactor) : 2; // Default nb Entries = 2 if(mMaxNbEntries < mCurNbEntries + needed) { mMaxNbEntries = mCurNbEntries + needed; } // Get some bytes for new entries TUInt32* NewEntries = new TUInt32[mMaxNbEntries]; CHECKALLOC(NewEntries); #ifdef CONTAINER_STATS // Add current amount of bytes mUsedRam+=mMaxNbEntries*sizeof(TUInt32); #endif // Copy old data if needed if(mCurNbEntries) { CopyMemory(NewEntries, mEntries, mCurNbEntries*sizeof(TUInt32)); } // Delete old data DELETEARRAY(mEntries); // Assign new pointer mEntries = NewEntries; return true; }
bool Container::SetSize(TUInt32 nb) { // Make sure it's empty Empty(); // Checkings if(!nb) { return false; } // Initialize for nb entries mMaxNbEntries = nb; // Get some bytes for new entries mEntries = new TUInt32[mMaxNbEntries]; CHECKALLOC(mEntries); #ifdef CONTAINER_STATS // Add current amount of bytes mUsedRam+=mMaxNbEntries*sizeof(TUInt32); #endif return true; }
static bool ExtensionSupported(const char* buf, const char* ext) { if(!buf) { SetIceError("Extensions string is null", null); return false; } long Length = strlen(buf); char* CurrentExt = new char[Length]; CHECKALLOC(CurrentExt); int j=0; while(buf[j]!='\0') { int i=0; while(buf[j]!=' ' && buf[j]!='\0') { CurrentExt[i++] = buf[j++]; if(i>=Length) { DELETEARRAY(CurrentExt); return SetIceError("Extensions string is too long!?", null); } } CurrentExt[i]='\0'; j++; if(strcmp(ext, CurrentExt)==0) { DELETEARRAY(CurrentExt); return true; } } DELETEARRAY(CurrentExt); return false; }