From e721e6b957228585cd9344b033628153564e8cdd Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Sun, 7 Aug 2011 10:22:23 +0100 Subject: [PATCH] protogen: memory hygeine. Organization: Straylight/Edgeware From: Richard Kettlewell --- lib/client-stubs.c | 28 ++++++++++++++++++++++++++++ scripts/protocol | 11 ++++++++--- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/lib/client-stubs.c b/lib/client-stubs.c index b6bc8e2..5898534 100644 --- a/lib/client-stubs.c +++ b/lib/client-stubs.c @@ -44,6 +44,8 @@ int disorder_confirm(disorder_client *c, const char *confirmation) { if(rc) return rc; c->user = v[0]; + v[0] = NULL; + free_strings(nv, v); return 0; } @@ -53,6 +55,8 @@ int disorder_cookie(disorder_client *c, const char *cookie) { if(rc) return rc; c->user = v[0]; + v[0] = NULL; + free_strings(nv, v); return 0; } @@ -88,6 +92,7 @@ int disorder_enabled(disorder_client *c, int *enabledp) { return rc; if(boolean("enabled", v[0], enabledp)) return -1; + free_strings(nv, v); return 0; } @@ -98,6 +103,7 @@ int disorder_exists(disorder_client *c, const char *track, int *existsp) { return rc; if(boolean("exists", v[0], existsp)) return -1; + free_strings(nv, v); return 0; } @@ -116,6 +122,8 @@ int disorder_get(disorder_client *c, const char *track, const char *pref, char * if(rc) return rc; *valuep = v[0]; + v[0] = NULL; + free_strings(nv, v); return 0; } @@ -125,6 +133,8 @@ int disorder_get_global(disorder_client *c, const char *pref, char **valuep) { if(rc) return rc; *valuep = v[0]; + v[0] = NULL; + free_strings(nv, v); return 0; } @@ -134,6 +144,7 @@ int disorder_length(disorder_client *c, const char *track, long *lengthp) { if(rc) return rc; *lengthp = atol(v[0]); + free_strings(nv, v); return 0; } @@ -143,6 +154,8 @@ int disorder_make_cookie(disorder_client *c, char **cookiep) { if(rc) return rc; *cookiep = v[0]; + v[0] = NULL; + free_strings(nv, v); return 0; } @@ -177,6 +190,8 @@ int disorder_part(disorder_client *c, const char *track, const char *context, co if(rc) return rc; *partp = v[0]; + v[0] = NULL; + free_strings(nv, v); return 0; } @@ -266,6 +281,7 @@ int disorder_random_enabled(disorder_client *c, int *enabledp) { return rc; if(boolean("random-enabled", v[0], enabledp)) return -1; + free_strings(nv, v); return 0; } @@ -288,6 +304,8 @@ int disorder_register(disorder_client *c, const char *username, const char *pass if(rc) return rc; *confirmationp = v[0]; + v[0] = NULL; + free_strings(nv, v); return 0; } @@ -309,6 +327,8 @@ int disorder_resolve(disorder_client *c, const char *track, char **resolvedp) { if(rc) return rc; *resolvedp = v[0]; + v[0] = NULL; + free_strings(nv, v); return 0; } @@ -326,7 +346,10 @@ int disorder_rtp_address(disorder_client *c, char **addressp, char **portp) { if(rc) return rc; *addressp = v[0]; + v[0] = NULL; *portp = v[1]; + v[1] = NULL; + free_strings(nv, v); return 0; } @@ -422,6 +445,8 @@ int disorder_userinfo(disorder_client *c, const char *username, const char *prop if(rc) return rc; *valuep = v[0]; + v[0] = NULL; + free_strings(nv, v); return 0; } @@ -440,6 +465,8 @@ int disorder_version(disorder_client *c, char **versionp) { if(rc) return rc; *versionp = v[0]; + v[0] = NULL; + free_strings(nv, v); return 0; } @@ -458,6 +485,7 @@ int disorder_get_volume(disorder_client *c, long *leftp, long *rightp) { return rc; *leftp = atol(v[0]); *rightp = atol(v[1]); + free_strings(nv, v); return 0; } diff --git a/scripts/protocol b/scripts/protocol index 39b7dd5..f2a0c80 100755 --- a/scripts/protocol +++ b/scripts/protocol @@ -308,7 +308,8 @@ sub simple { my $name = $return->[1]; if($type eq 'string') { push(@c, - " *${name}p = v[$n];\n"); + " *${name}p = v[$n];\n", + " v[$n] = NULL;\n"); } elsif($type eq 'boolean') { push(@c, " if(boolean(\"$cmd\", v[$n], ${name}p))\n", @@ -321,7 +322,8 @@ sub simple { " *${name}p = atoll(v[$n]);\n"); } elsif($type eq 'user') { push(@c, - " c->user = v[$n];\n"); + " c->user = v[$n];\n", + " v[$n] = NULL;\n"); } elsif($type eq 'body') { push(@c, " if(readlist(c, ${name}p, n${name}p))\n", @@ -334,8 +336,11 @@ sub simple { die "$0: C API: unknown return type '$type' for '$name'\n"; } } + if($expected) { + push(@c, + " free_strings(nv, v);\n"); + } push(@c, " return 0;\n"); - # TODO xfree unconsumed split output } push(@c, "}\n\n"); -- [mdw]