Maybe you could help me with the following code...
int main()
{
char foo = '?'; // foo is created on the stack.
char* bar = "Hello World"; // where is bar created?
// will the following result as a NOP or undefined behavior?
free(bar);
return 0;
}
What about this:
struct Foo
{
char* value;
};
struct Foo a = {"Hello from variable a"}; // are a and b created in the .data segment of the asm?
struct Foo b = {"Hello from variable b"};
int main()
{
// what will happen here:
struct Foo* ptr = &a;
free(ptr); // error?
// what about this:
struct Foo* bar = (struct Foo*)malloc(sizeof(struct Foo));
bar = &b;
bar->value = (char*)malloc(sizeof(char)*2); // what happened to the the original contents of bar->value?
bar->value[0] = 'H';
bar->value[1] = 'i';
free(bar->value);
free(bar); // is this an error?
return 0;
}