G
googler
Hello, I have a very simple question that I'm a bit confused about
right now. Is it OK to allocate memory by malloc() or calloc() for a
struct member and then call free() on it? For example, I have the code
below.
struct mystruct {
int a;
char *b;
int c;
};
struct mystruct myobject;
myobject.b = (char *)malloc(50);
....
....
free(myobject.b);
Is the above code OK, or is there any potential problem with it?
Thanks!
right now. Is it OK to allocate memory by malloc() or calloc() for a
struct member and then call free() on it? For example, I have the code
below.
struct mystruct {
int a;
char *b;
int c;
};
struct mystruct myobject;
myobject.b = (char *)malloc(50);
....
....
free(myobject.b);
Is the above code OK, or is there any potential problem with it?
Thanks!