這是我的函數,其中我調試:Ç - free()的錯誤
boolean
adin_memory(char* buffer, int size_chunck, int end_flag){
global_buffer = mymalloc(size_chunck*sizeof(char)); //3
global_buffer = buffer;
real_data= (SP16 *)mymalloc(size_chunck*sizeof(SP16)); //3
memcpy(real_data,global_buffer,size_chunck);
free(global_buffer); //ERROR
pos_escrita += size_chunck;
global_size = size_chunck;
global_end_flag = end_flag;
return TRUE;
}
這是mymalloc
功能:
void *
mymalloc(size_t size)
{
void *p;
if ((p = malloc(size)) == NULL) {
#if defined(_WIN32) && !defined(__CYGWIN32__)
jlog("Error: mymalloc: failed to allocate %Iu bytes\n", size);
#else
jlog("Error: mymalloc: failed to allocate %zu bytes\n", size);
#endif
*((char*)0) = 0 ; //###ARL provoca um exception
exit(1);
}
return p;
}
@ user3121023這應該是一個答案(和順便說一句,'global_buffer'無處被定義這段代碼似乎確實是一個全局變量......非常奇怪) –
建議根據廣泛使用的約定,調用一個'malloc()'-wrapper檢查OOM xmalloc()。 –
進一步建議不要投射從'malloc()'(或更一般的'void *'指針)返回的指針 –