// Mark as free
head->Magic = MAGIC_FREE;
+ head->File = NULL;
+ head->Line = 0;
+ head->ValidSize = 0;
// Merge blocks
Heap_Merge( head );
}
/**
+ * \brief Increase/Decrease the size of an allocation
+ * \param File Calling File
+ * \param Line Calling Line
+ * \param __ptr Old memory
+ * \param __size New Size
*/
void *Heap_Reallocate(const char *File, int Line, void *__ptr, size_t __size)
{
// Exact Fit
if(size == newSize) {
head->Size = newSize;
+ head->ValidSize = __size;
head->File = File;
head->Line = Line;
foot->Head = head;
head->Size = newSize; // Edit first header
head->File = File;
head->Line = Line;
+ head->ValidSize = __size;
// Create new footer
foot = (void*)( (Uint)head + newSize - sizeof(tHeapFoot) );
foot->Head = head;
nextHead->Size = newSize;
nextHead->File = File;
nextHead->Line = Line;
+ nextHead->ValidSize = __size;
// Get 2nd (old) footer
foot = (void*)( (Uint)nextHead + newSize );
foot->Head = nextHead;
nextHead -= 1;
nextHead->File = File;
nextHead->Line = Line;
+ nextHead->ValidSize = __size;
memcpy(
nextHead->Data,
while( (Uint)head < (Uint)gHeapEnd )
{
foot = (void*)( (Uint)head + head->Size - sizeof(tHeapFoot) );
- Log_Log("Heap", "%p (0x%llx): 0x%08lx %4C",
- head, MM_GetPhysAddr((Uint)head), head->Size, &head->Magic);
+ Log_Log("Heap", "%p (0x%llx): 0x%08lx (%i) %4C",
+ head, MM_GetPhysAddr((Uint)head), head->Size, head->ValidSize, &head->Magic);
Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic);
if(head->File) {
Log_Log("Heap", "%sowned by %s:%i",
head = foot->Head;
while( (tVAddr)head >= (tVAddr)badHead )
{
- Log_Log("Heap", "%p (0x%llx): 0x%08lx %4C",
- head, MM_GetPhysAddr((Uint)head), head->Size, &head->Magic);
+ Log_Log("Heap", "%p (0x%llx): 0x%08lx %i %4C",
+ head, MM_GetPhysAddr((Uint)head), head->Size, head->ValidSize, &head->Magic);
Log_Log("Heap", "%p %4C", foot->Head, &foot->Magic);
if(head->File)
Log_Log("Heap", "%sowned by %s:%i",
LEAVE('p', curNode);
return curNode;
}
- // For root we always fast return
+ // For root we always fast return
if(Path[0] == '/' && Path[1] == '\0') {
if(TruePath) {
*TruePath = malloc( gVFS_RootMount->MountPointLen+1 );
return gVFS_RootMount->RootNode;
}
- // Check if there is anything mounted
+ // Check if there is an`ything mounted
if(!gVFS_Mounts) {
Warning("WTF! There's nothing mounted?");
return NULL;
curNode->ReferenceCount ++;
// Parse Path
ofs = mnt->MountPointLen+1;
- for(; (nextSlash = strpos(&Path[ofs], '/')) != -1; ofs = nextSlash + 1)
+ for(; (nextSlash = strpos(&Path[ofs], '/')) != -1; ofs += nextSlash + 1)
{
char pathEle[nextSlash+1];
free(*TruePath);
*TruePath = NULL;
}
- tmp = malloc( curNode->Size + 1 );
if(!curNode->Read) {
Warning("VFS_ParsePath - Read of node %p is NULL (%s)",
curNode, Path);
if(curNode->Close) curNode->Close(curNode);
+ // No need to free *TruePath, see above
+ LEAVE('n');
+ return NULL;
+ }
+
+ tmp = malloc( curNode->Size + 1 );
+ if(!tmp) {
+ Log_Warning("VFS", "VFS_ParsePath - Malloc failure");
+ // No need to free *TruePath, see above
LEAVE('n');
return NULL;
}
// Parse Symlink Path
curNode = VFS_ParsePath(tmp, TruePath);
if(TruePath)
- Log_Debug("VFS", "*TruePath='%s'", *TruePath);
+ LOG("VFS", "*TruePath='%s'", *TruePath);
// Error Check
if(!curNode) {
- Log("Symlink fail '%s'", tmp);
+ Log_Debug("VFS", "Symlink fail '%s'", tmp);
free(tmp); // Free temp string
+ if(TruePath) free(TruePath);
LEAVE('n');
return NULL;
}
if(!TruePath) continue;
// Increase buffer space
- tmp = realloc( *TruePath, retLength + strlen(&Path[ofs]) + 1 + 1 );
+ tmp = realloc( *TruePath, retLength + strlen(pathEle) + 1 + 1 );
// Check if allocation succeeded
if(!tmp) {
Warning("VFS_ParsePath - Unable to reallocate true path buffer");
free(*TruePath);
+ *TruePath = NULL;
if(curNode->Close) curNode->Close(curNode);
LEAVE('n');
return NULL;
// Append to path
(*TruePath)[retLength] = '/';
strcpy(*TruePath+retLength+1, pathEle);
+
+ LOG("*TruePath = '%s'\n", *TruePath);
+
// - Extend Path
- retLength += nextSlash;
+ retLength += nextSlash + 1;
}
// Get last node