On 2021-03-11 13:54:56, Michael Dukelsky (2:5020/1042) wrote to andrew clarke:
PH>>>> double free or corruption (fasttop)
PH>>>> Aborted
ac>> This is likely due to free() being called twice on the same pointer
ac>> somewhere in the Linux build of HTick.
MD> OK, thank you. It should be easy to fix.
nfree() may help but it's not foolproof. Consider this:
#include
#include
#include
#define nfree(a) {if(a != NULL) {free(a); a = NULL;}}
static void foo(char *p)
{
printf("%s\n", p);
nfree(p);
}
int main(void)
{
char *p = malloc(42);
strcpy(p, "Hello!");
foo(p);
nfree(p);
return 0;
}
Here foo() can only set its local copy of p to NULL. It can't modify the original pointer.
There's not really any way around this kind of mistake in C, other than to run it through a debugger, examine the code and fix it by hand.
--- GoldED+/BSD 1.1.5-b20180707
* Origin: Blizzard of Ozz, Melbourne, Victoria, Australia (3:633/267)
|