diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-03-29 00:23:49 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-03-29 00:23:49 +1300 |
commit | 489f68072f95b68722b73cc53ceb5b839d997e42 (patch) | |
tree | ea9c3d00aba1b8a6176ba7fd665c3886b2dbf6d4 | |
parent | Remove overdressed bracing (diff) | |
download | btree-489f68072f95b68722b73cc53ceb5b839d997e42.tar.gz btree-489f68072f95b68722b73cc53ceb5b839d997e42.zip |
Copy the arg strings rather than sharing them
Avoiding strdup(3) as I'm still playing the C90-only game
-rw-r--r-- | btree-str.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/btree-str.c b/btree-str.c index 1e0903a..ff2338e 100644 --- a/btree-str.c +++ b/btree-str.c @@ -42,6 +42,7 @@ void fn(Node *n) { fn(n->l); if (n->r) fn(n->r); + free(n->v); free(n); return; } @@ -50,8 +51,13 @@ int main(int argc, char **argv) { Node *r = NULL; for (argv++, argc--; argc; argv++, argc--) { + unsigned long l = 0; Node *n = malloc(sizeof(Node)); - n->v = *argv; + + l = strlen(*argv) + 1; + n->v = malloc(l); + strncpy(n->v, *argv, l); + n->l = n->r = NULL; an(&r, n); } |