A more object-oriented way of handling this sort of structure is to define functions for both allocating and freeing such structures.
(Improved version of this code)
// Allocate a GP object
Generic_Properties * create_GP()
{
Generic_Properties * p;
p = malloc(sizeof(Generic_Properties));
memset(p, 0, sizeof(*p));
return p;
}
// Deallocate a GP object
void free_GP(Generic_Properties *p)
{
if (p == NULL)
return;
free(p->ID);
p->ID = NULL;
free(p->name);
p->name = NULL;
free(p);
}
Addendum
If you want to combine this approach with @Alter Mann's approach, you can do something like this:
// Allocate a GP object
Generic_Properties * create_GP2(const char *id, const char *name)
{
size_t idLen;
size_t nameLen;
Generic_Properties * p;
// Reserve space for GP, GP.ID, and GP.name
// all in one malloc'd block
idLen = strlen(id) + 1;
nameLen = strlen(name) + 1;
p = malloc(sizeof(Generic_Properties) + idLen + nameLen);
memset(p, 0, sizeof(*p));
// Save the ID
p->ID = (char *)p + sizeof(Generic_Properties);
memcpy(p->ID, id, idLen);
// Save the name
p->name = p->ID + idLen;
memcpy(p->name, name, nameLen);
return p;
}
// Deallocate a GP object
void free_GP2(Generic_Properties *p)
{
free(p);
}