fixes demo to show how to free the resources

This commit is contained in:
overflowerror 2021-05-04 17:07:51 +02:00
parent fcf69c17c8
commit 7590a1acd7
2 changed files with 9 additions and 5 deletions

View file

@ -29,12 +29,16 @@ int main() {
printf("User.Email: %s\n", post->user.email);
printf("\n");
free(post->content);
post->content = "Just do it.";
char* newJson = json_marshall(post_t, post);
printf("%s\n", newJson);
free(newJson);
// set to NULL so it doesn't get freed
post->content = NULL;
json_free_struct(post_t, post);
return 0;
}

View file

@ -4,13 +4,13 @@
typedef struct {
long long uid;
const char* username;
const char* email;
char* username;
char* email;
} user_t;
typedef struct {
const char* name;
const char* content;
char* name;
char* content;
long* views;
user_t user;
} post_t;