void FLZOFile::Explode () { unsigned int expandsize, cprlen; unsigned char *expand; if (m_Buffer) { unsigned int *ints = (unsigned int *)(m_Buffer); cprlen = BELONG(ints[0]); expandsize = BELONG(ints[1]); expand = (unsigned char *)Malloc (expandsize); if (cprlen) { unsigned int r; lzo_uint newlen = expandsize; r = lzo1x_decompress_safe (m_Buffer + 8, cprlen, expand, &newlen, NULL); if (r != LZO_E_OK || newlen != expandsize) { M_Free(expand); I_Error ("Could not decompress LZO file"); } } else { memcpy (expand, m_Buffer + 8, expandsize); } if (FreeOnExplode ()) M_Free(m_Buffer); m_Buffer = expand; m_BufferSize = expandsize; } }
void Z_Shutdown(void) { int numVolumes = 0; size_t totalMemory = 0; // Get rid of possible zone-allocated memory in the garbage. Garbage_RecycleAllWithDestructor(Z_Free); // Destroy all the memory volumes. while (volumeRoot) { memvolume_t *vol = volumeRoot; volumeRoot = vol->next; // Calculate stats. numVolumes++; totalMemory += vol->size; #ifdef LIBDENG_FAKE_MEMORY_ZONE Z_FreeTags(0, DDMAXINT); #endif M_Free(vol->zone); M_Free(vol); } App_Log(DE2_LOG_NOTE, "Z_Shutdown: Used %i volumes, total %u bytes.", numVolumes, totalMemory); Sys_DestroyMutex(zoneMutex); zoneMutex = 0; }
// // W_InitMultipleFiles // Pass a null terminated list of files to use. // All files are optional, but at least one file // must be found. // Files with a .wad extension are idlink files // with multiple lumps. // Other files are single lumps with the base filename // for the lump name. // Lump names can appear multiple times. // The name searcher looks backwards, so a later file // does override all earlier ones. // std::vector<std::string> W_InitMultipleFiles (std::vector<std::string> &filenames) { size_t size, i; // open all the files, load headers, and count lumps // will be realloced as lumps are added numlumps = 0; M_Free(lumpinfo); std::vector<std::string> hashes(filenames); // open each file once, load headers, and count lumps int j = 0; std::vector<std::string> loaded; for(i = 0; i < filenames.size(); i++) { if(std::find(loaded.begin(), loaded.end(), filenames[i].c_str()) == loaded.end()) { hashes[j++] = W_AddFile(filenames[i].c_str()); loaded.push_back(filenames[i].c_str()); } } filenames = loaded; hashes.resize(j); if (!numlumps) I_Error ("W_InitFiles: no files found"); // [RH] Set namespace markers to global for everything for (i = 0; i < numlumps; i++) lumpinfo[i].namespc = ns_global; // [RH] Merge sprite and flat groups. // (We don't need to bother with patches, since // Doom doesn't use markers to identify them.) W_MergeLumps ("S_START", "S_END", ns_sprites); // denis - fixme - security W_MergeLumps ("F_START", "F_END", ns_flats); W_MergeLumps ("C_START", "C_END", ns_colormaps); // set up caching M_Free(lumpcache); size = numlumps * sizeof(*lumpcache); lumpcache = (void **)Malloc (size); if (!lumpcache) I_Error ("Couldn't allocate lumpcache"); memset (lumpcache,0, size); // killough 1/31/98: initialize lump hash table W_HashLumps(); stdisk_lumpnum = W_GetNumForName("STDISK"); return hashes; }
Id1Map::~Id1Map() { if(vertexes) { M_Free(vertexes); vertexes = 0; } DENG2_FOR_EACH(Polyobjs, i, polyobjs) { M_Free(i->lineIndices); }
PClass::~PClass() { if (Defaults != nullptr) { M_Free(Defaults); Defaults = nullptr; } if (Meta != nullptr) { M_Free(Meta); Meta = nullptr; } }
void FTextureManager::AddSwitchPair (FSwitchDef *def1, FSwitchDef *def2) { unsigned int i; FSwitchDef *sw1 = NULL; FSwitchDef *sw2 = NULL; unsigned int index1 = 0xffffffff, index2 = 0xffffffff; for (i = mSwitchDefs.Size (); i-- > 0; ) { if (mSwitchDefs[i]->PreTexture == def1->PreTexture) { index1 = i; sw1 = mSwitchDefs[index1]; if (index2 != 0xffffffff) break; } if (mSwitchDefs[i]->PreTexture == def2->PreTexture) { index2 = i; sw2 = mSwitchDefs[index2]; if (index1 != 0xffffffff) break; } } def1->PairDef = def2; def2->PairDef = def1; if (sw1 != NULL && sw2 != NULL && sw1->PairDef == sw2 && sw2->PairDef == sw1) { //We are replacing an existing pair so we can safely delete the old definitions M_Free(sw1); M_Free(sw2); mSwitchDefs[index1] = def1; mSwitchDefs[index2] = def2; } else { // This new switch will not or only partially replace an existing pair. // We should not break up an old pair if the new one only redefined one // of the two textures. These paired definitions will only be used // as the return animation so their names don't matter. Better clear them to be safe. if (sw1 != NULL) sw1->PreTexture.SetInvalid(); if (sw2 != NULL) sw2->PreTexture.SetInvalid(); sw1 = NULL; sw2 = NULL; unsigned int pos = mSwitchDefs.Reserve(2); mSwitchDefs[pos] = def1; mSwitchDefs[pos+1] = def2; } }
void FTextureManager::DeleteAll() { for (unsigned int i = 0; i < Textures.Size(); ++i) { delete Textures[i].Texture; } Textures.Clear(); Translation.Clear(); FirstTextureForFile.Clear(); memset (HashFirst, -1, sizeof(HashFirst)); DefaultTexture.SetInvalid(); for (unsigned i = 0; i < mAnimations.Size(); i++) { if (mAnimations[i] != NULL) { M_Free (mAnimations[i]); mAnimations[i] = NULL; } } mAnimations.Clear(); for (unsigned i = 0; i < mSwitchDefs.Size(); i++) { if (mSwitchDefs[i] != NULL) { M_Free (mSwitchDefs[i]); mSwitchDefs[i] = NULL; } } mSwitchDefs.Clear(); for (unsigned i = 0; i < mAnimatedDoors.Size(); i++) { if (mAnimatedDoors[i].TextureFrames != NULL) { delete mAnimatedDoors[i].TextureFrames; mAnimatedDoors[i].TextureFrames = NULL; } } mAnimatedDoors.Clear(); for (unsigned int i = 0; i < BuildTileFiles.Size(); ++i) { delete[] BuildTileFiles[i]; } BuildTileFiles.Clear(); }
void FStateDefinitions::InstallStates(PClassActor *info, AActor *defaults) { // First ensure we have a valid spawn state. FState *state = FindState("Spawn"); if (state == NULL) { // A NULL spawn state will crash the engine so set it to something valid. SetStateLabel("Spawn", GetDefault<AActor>()->SpawnState); } if (info->StateList != NULL) { info->StateList->Destroy(); M_Free(info->StateList); } info->StateList = CreateStateLabelList(StateLabels); // Cache these states as member veriables. defaults->SpawnState = info->FindState(NAME_Spawn); defaults->SeeState = info->FindState(NAME_See); // Melee and Missile states are manipulated by the scripted marines so they // have to be stored locally defaults->MeleeState = info->FindState(NAME_Melee); defaults->MissileState = info->FindState(NAME_Missile); }
ddstring_t *Str_PartAppend(ddstring_t *str, char const *append, int start, int count) { int partLen; char *copied; DENG_ASSERT(str); DENG_ASSERT(append); if(!str || !append) return str; if(start < 0 || count <= 0) return str; copied = M_Malloc(count + 1); copied[0] = 0; // empty string strncat(copied, append + start, count); partLen = strlen(copied); allocateString(str, str->length + partLen + 1, true); memcpy(str->str + str->length, copied, partLen); str->length += partLen; // Terminate the appended part. str->str[str->length] = 0; M_Free(copied); return str; }
ddstring_t *Str_Prepend(ddstring_t *str, char const *prepend) { char *copied; size_t incoming; DENG_ASSERT(str); DENG_ASSERT(prepend); if(!str || !prepend) return str; incoming = strlen(prepend); if(incoming == 0) return str; copied = M_Malloc(incoming); memcpy(copied, prepend, incoming); allocateString(str, str->length + incoming, true); memmove(str->str + incoming, str->str, str->length + 1); memcpy(str->str, copied, incoming); str->length += incoming; M_Free(copied); return str; }
void Rectf_Delete(Rectf *r) { DENG_ASSERT(r); Point2f_Delete(r->origin); Size2f_Delete(r->size); M_Free(r); }
void Rect_Delete(Rect *r) { if(!r) return; Point2_Delete(r->origin); Size2_Delete(r->size); M_Free(r); }
void FStringTable::SetString (const char *name, const char *newString) { StringEntry **pentry, *oentry; FindString (name, pentry, oentry); size_t newlen = strlen (newString); size_t namelen = strlen (name); // Create a new string entry StringEntry *entry = (StringEntry *)M_Malloc (sizeof(*entry) + newlen + namelen); strcpy (entry->String, newString); strcpy (entry->Name = entry->String + newlen + 1, name); entry->PassNum = 0; // If this is a new string, insert it. Otherwise, replace the old one. if (oentry == NULL) { entry->Next = *pentry; *pentry = entry; } else { *pentry = entry; entry->Next = oentry->Next; M_Free (oentry); } }
static FDoubleProd *StringToDouble (FProduction *prod) { FDoubleProd *newprod; newprod = NewDoubleProd (atof (static_cast<FStringProd *>(prod)->Value)); M_Free (prod); return newprod; }
static void deleteString(Str *str) { DENG_ASSERT(str); if(!str) return; Str_Free(str); M_Free(str); }
FArchive::~FArchive () { Close (); if (m_TypeMap) delete[] m_TypeMap; if (m_ObjectMap) M_Free(m_ObjectMap); }
void FMemArena::FreeBlockChain(Block *&top) { for (Block *next, *block = top; block != NULL; block = next) { next = block->NextBlock; M_Free(block); } top = NULL; }
size_t Zip::readLump(int lumpIdx, uint8_t* buffer, size_t startOffset, size_t length, bool tryCache) { LOG_AS("Zip::readLump"); ZipFile const& file = reinterpret_cast<ZipFile&>(lump(lumpIdx)); LOG_TRACE("\"%s:%s\" (%u bytes%s) [%u +%u]") << de::NativePath(composePath()).pretty() << de::NativePath(file.composePath()).pretty() << (unsigned long) file.size() << (file.isCompressed()? ", compressed" : "") << startOffset << length; // Try to avoid a file system read by checking for a cached copy. if(tryCache) { uint8_t const* data = d->lumpCache? d->lumpCache->data(lumpIdx) : 0; LOG_TRACE("Cache %s on #%i") << (data? "hit" : "miss") << lumpIdx; if(data) { size_t readBytes = MIN_OF(file.size(), length); memcpy(buffer, data + startOffset, readBytes); return readBytes; } } size_t readBytes; if(!startOffset && length == file.size()) { // Read it straight to the caller's data buffer. readBytes = d->bufferLump(file, buffer); } else { // Allocate a temporary buffer and read the whole lump into it(!). uint8_t* lumpData = (uint8_t*) M_Malloc(file.size()); if(!lumpData) throw Error("Zip::readLumpSection", QString("Failed on allocation of %1 bytes for work buffer").arg(file.size())); if(d->bufferLump(file, lumpData)) { readBytes = MIN_OF(file.size(), length); memcpy(buffer, lumpData + startOffset, readBytes); } else { readBytes = 0; } M_Free(lumpData); } /// @todo Do not check the read length here. if(readBytes < MIN_OF(file.size(), length)) throw Error("Zip::readLumpSection", QString("Only read %1 of %2 bytes of lump #%3").arg(readBytes).arg(length).arg(lumpIdx)); return readBytes; }
void PClass::FreeStateList () { if (ActorInfo != NULL && ActorInfo->StateList != NULL) { ActorInfo->StateList->Destroy(); M_Free (ActorInfo->StateList); ActorInfo->StateList = NULL; } }
void SV_ClearTargetPlayers() { while(targetPlayerAddrs) { targetplraddress_t *next = targetPlayerAddrs->next; M_Free(targetPlayerAddrs); targetPlayerAddrs = next; } }
/** * Frees the message. */ void N_ReleaseMessage(netmessage_t *msg) { if(msg->handle) { delete [] reinterpret_cast<byte *>(msg->handle); msg->handle = 0; } M_Free(msg); }
FName::NameManager::~NameManager() { NameBlock *block, *next; for (block = Blocks; block != NULL; block = next) { next = block->NextBlock; M_Free (block); } Blocks = NULL; if (NameArray != NULL) { M_Free (NameArray); NameArray = NULL; } NumNames = MaxNames = 0; memset (Buckets, -1, sizeof(Buckets)); }
static FStringProd *DoubleToString (FProduction *prod) { char buf[128]; FStringProd *newprod; mysnprintf (buf, countof(buf), "%g", static_cast<FDoubleProd *>(prod)->Value); newprod = NewStringProd (buf); M_Free (prod); return newprod; }
AnimArray::~AnimArray() { for (unsigned i = 0; i < Size(); i++) { if ((*this)[i] != NULL) { M_Free ((*this)[i]); (*this)[i] = NULL; } } }
void R_3D_DeleteHeights() { height_cur = height_top; while(height_cur) { height_top = height_cur; height_cur = height_cur->next; M_Free(height_top); } height_max = -1; height_top = height_cur = NULL; }
void FRemapTable::Free() { KillNative(); if (Remap != NULL) { M_Free(Remap); Remap = NULL; Palette = NULL; NumEntries = 0; } }
FArchive::~FArchive () { Close (); delete[] m_TypeMap; m_TypeMap = NULL; if (m_ObjectMap) { M_Free(m_ObjectMap); } }
void C_InitConsole (int width, int height, BOOL ingame) { int row; char *zap; char *old; int cols, rows; cols = ConCols; rows = ConRows; ConCols = width / 8 - 2; PhysRows = height / 8; ConRows = PhysRows * 10; old = Lines; Lines = (char *)Malloc (ConRows * (ConCols + 2) + 1); for (row = 0, zap = Lines; row < ConRows; row++, zap += ConCols + 2) { zap[0] = 0; zap[1] = 0; } Last = Lines + (ConRows - 1) * (ConCols + 2); if (old) { char string[256]; gamestate_t oldstate = gamestate; // Don't print during reformatting gamestate = GS_FORCEWIPE; for (row = 0, zap = old; row < rows; row++, zap += cols + 2) { memcpy (string, &zap[2], zap[1]); if (!zap[0]) { string[(int)zap[1]] = '\n'; string[zap[1]+1] = 0; } else { string[(int)zap[1]] = 0; } Printf (PRINT_HIGH, "%s", string); } M_Free (old); C_FlushDisplay (); gamestate = oldstate; } }
/** * Destroys a command binding. * * @param eb Command binding to destroy. */ void B_DestroyCommandBinding(evbinding_t* eb) { if(!eb) return; assert(eb->bid != 0); // Unlink first, if linked. if(eb->prev) { eb->prev->next = eb->next; eb->next->prev = eb->prev; } if(eb->command) M_Free(eb->command); if(eb->conds) M_Free(eb->conds); free(eb->symbolicName); M_Free(eb); }
void FStringTable::FreeData () { for (int i = 0; i < HASH_SIZE; ++i) { StringEntry *entry = Buckets[i], *next; Buckets[i] = NULL; while (entry != NULL) { next = entry->Next; M_Free (entry); entry = next; } } }