This stuff drives me nuts. I'm trying to figure out how to reference this struct properly passing a pointer to it between functions and manipulating it...
Typedef for the struct:
Code:
typedef unsigned char u8;
typedef unsigned short int u16;
typedef unsigned int u32;
typedef unsigned long long int u64;
//These are the vars included in the header of the binary results files.
typedef struct CODE_SEARCH_RESULTS_INFO {
char dmpFileName[MAX_PATH];
int Endian;
int SearchSize;
u32 DumpSize;
u32 ResCount;
u32 ResHigh; //highest result file address
u32 MapFileAddy[MAX_MAPPED_AREAS]; //file address
u32 MapMemAddy[MAX_MAPPED_AREAS]; //memory address
} CODE_SEARCH_RESULTS_INFO;
//dump data and results during searches
typedef struct _RAM_AND_RES_DATA {
int Access;
u8 *NewRAM;
u8 *OldRAM;
FILE *NewFile;
FILE *OldFile;
u8 *Results;
CODE_SEARCH_RESULTS_INFO OldResultsInfo;
CODE_SEARCH_RESULTS_INFO NewResultsInfo;
} RAM_AND_RES_DATA;
Example use:
Code:
RAM_AND_RES_DATA RamInfo; memset(&RamInfo,0,sizeof(RAM_AND_RES_DATA));
//malloc RamInfo.NewRAM, etc here or send to function to load data into etc //
//when finished:
FreeRamInfo(&RamInfo);
The confusion part:
Code:
int FreeRamInfo(RAM_AND_RES_DATA *RamInfo)
{
if (RamInfo->NewRAM) { free(RamInfo->NewRAM); RamInfo->NewRAM = NULL; }
if (RamInfo->OldRAM) { free(RamInfo->OldRAM); RamInfo->OldRAM = NULL; }
if (RamInfo->NewFile) { fclose(RamInfo->NewFile); RamInfo->NewFile = NULL; }
if (RamInfo->OldFile) { fclose(RamInfo->OldFile); RamInfo->OldFile = NULL; }
if (RamInfo->Results) { free(RamInfo->Results); RamInfo->Results = NULL; }
memset(&RamInfo.OldResultsInfo, 0, sizeof(CODE_SEARCH_RESULTS_INFO));
memset(&RamInfo.NewResultsInfo, 0, sizeof(CODE_SEARCH_RESULTS_INFO));
return 0;
}
Is FreeRamInfo anywhere near right? I plan to use the same struct in multiple parts of the app (but only come elements some of the time), so I want a shortcut to free up whatever was allocated etc. I'd also like to send the pointer of say RamInfo.NewRAM to a FileLoad function and malloc from there, but I always had issues trying to do that. I don't know if I was doing it wrong, or if malloc just has to take place locally. The only way I ever got it to work was by making RamInfo a global, which I'm trying to avoid now.