diff options
author | Joshua Haberman <joshua@reverberate.org> | 2009-08-07 21:05:27 -0700 |
---|---|---|
committer | Joshua Haberman <joshua@reverberate.org> | 2009-08-07 21:05:27 -0700 |
commit | eb67fb9109a24d866fe81abe4dd221e6fe18416f (patch) | |
tree | d11d169af8ffbe60fd84667b364c0a9f458018b1 /tools/upbc.c | |
parent | 8fa6a92f534cb01b6f5b4f48e3982f686d6c3123 (diff) |
Fixed memory leaks in upbc.
Diffstat (limited to 'tools/upbc.c')
-rw-r--r-- | tools/upbc.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tools/upbc.c b/tools/upbc.c index 28991a5..f593ae9 100644 --- a/tools/upbc.c +++ b/tools/upbc.c @@ -434,6 +434,7 @@ static void write_message_c(void *data, struct upb_msgdef *m, fprintf(stream, " {.ptr = &strdata[%d], .byte_len=%d},\n", e->offset, e->e.key.byte_len); } fputs("};\n\n", stream); + free(str_entries); /* Gather a list of types for which we are emitting data, and give each msg * a unique number within its type. */ @@ -568,6 +569,15 @@ static void write_message_c(void *data, struct upb_msgdef *m, fprintf(stream, UPB_STRFMT " *%s = &" UPB_STRFMT "_values[0];\n", UPB_STRARG(toplevel_type->cident), cident, UPB_STRARG(toplevel_type->cident)); + + /* Free tables. */ + for(e = upb_strtable_begin(&types); e; e = upb_strtable_next(&types, &e->e)) { + upb_strfree(e->cident); + free(e->values); + free(e->arrays); + } + upb_strtable_free(&types); + upb_strtable_free(&strings); } const char usage[] = @@ -669,12 +679,14 @@ int main(int argc, char *argv[]) int symcount; struct upb_symtab_entry **entries = strtable_to_array(&c.symtab, &symcount); write_h(entries, symcount, h_filename, cident, h_file); + free(entries); if(cident) { FILE *c_file = fopen(c_filename, "w"); if(!c_file) error("Failed to open .h output file"); write_message_c(fds, c.fds_msg, cident, h_filename, argc, argv, input_file, c_file); fclose(c_file); } + upb_msg_free(fds, c.fds_msg); upb_context_free(&c); upb_strfree(descriptor); fclose(h_file); |