char *str = "hi!";
uList *l = (uList*) malloc(sizeof(uList));
uListIter *i = (uListIter*) malloc(sizeof(uListIter));
l->first = i;
i->val = strdup(str);
free(i->val);
i->val = NULL;
free(i); /* here is the error, it corrupts the heap */
free(l);
typedef struct Poo {
void* element;
int o;
} Poo;
int main(void)
{
char* str = "hey!";
Poo *p = (Poo*) malloc(sizeof(*p));
p->o = 3;
free(p); /* error here!!!!!!!!!!!!!!!!!!!!! */
scanf_s("h");
return 0;
}
$ cat lol.c
#include <stdio.h>
#include <stdlib.h>
typedef struct Poo {
void* element;
int o;
} Poo;
int main(void)
{
char* str = "hey!";
Poo *p = (Poo*) malloc(sizeof(*p));
p->o = 3;
free(p); /* error here!!!!!!!!!!!!!!!!!!!!! */
return 0;
}
$ clang lol.c -o lol
$ ./lol
$ #no error
extern "C" {
void foobar()
{
}
}
#include <stdio.h>
#include <stdlib.h>
typedef struct Poo {
void* element;
int o;
} Poo;
int main(void)
{
char* str = "hey!";
Poo *p = (Poo*) malloc(sizeof(*p)); /* should be Poo *p = (Poo*) malloc(sizeof(Poo)); other wise you are declaring a space of memory the size of a pointer so on 32bit systems 4 bytes 64bit 8bytes */
p->o = 3;
free(p); /* error here!!!!!!!!!!!!!!!!!!!!! */
return 0;
}
I have created my own list container structure, but I don't know if I'm using strtok correctly.
I don't know if that is enough code to go off of to help me, but here is the output when I try to
make a word list: