Fixed bugs and memory leaks.

pull/13171/head
Joshua Haberman 16 years ago
parent 485b964662
commit 9eaab71e99
  1. 4
      Makefile
  2. 20
      upb_context.c
  3. 4
      upb_msg.c

@ -3,11 +3,11 @@
CC=gcc
CXX=g++
CFLAGS=-std=c99
CPPFLAGS=-Wall -Wextra -pedantic -g -DUPB_UNALIGNED_READS_OK -fomit-frame-pointer
CPPFLAGS=-O0 -Wall -Wextra -pedantic -g -DUPB_UNALIGNED_READS_OK -fomit-frame-pointer
OBJ=upb_parse.o upb_table.o upb_msg.o upb_context.o descriptor.o
all: $(OBJ) test_table tests
clean:
rm -f $(OBJ) tests
rm -f *.o test_table tests
libupb.a: $(OBJ)
ar rcs libupb.a $(OBJ)

@ -34,6 +34,16 @@ bool upb_context_init(struct upb_context *c)
void upb_context_free(struct upb_context *c)
{
struct upb_symtab_entry *e = upb_strtable_begin(&c->symtab);
for(; e; e = upb_strtable_next(&c->symtab, &e->e)) {
switch(e->type) {
case UPB_SYM_MESSAGE: upb_msg_free(e->ref.msg); break;
case UPB_SYM_ENUM: upb_enum_free(e->ref._enum); break;
default: break; /* TODO */
}
free(e->ref.msg); /* The pointer is the same for all. */
free(e->e.key.ptr);
}
upb_strtable_free(&c->symtab);
for(size_t i = 0; i < c->fd_len; i++) free(c->fd[i]);
free(c->fd);
@ -165,8 +175,6 @@ static bool insert_message(struct upb_strtable *t,
return false;
}
upb_strtable_insert(t, &e.e);
printf("Inserted ");
upb_print(&e.e.key);
/* Add nested messages and enums. */
//if(d->set_flags.has.nested_type)
@ -175,7 +183,8 @@ static bool insert_message(struct upb_strtable *t,
if(!insert_message(t, d->nested_type->elements[i], &fqname))
return false;
if(d->set_flags.has.enum_type)
//if(d->set_flags.has.enum_type)
if(d->enum_type)
for(unsigned int i = 0; i < d->enum_type->len; i++)
if(!insert_enum(t, d->enum_type->elements[i], &fqname))
return false;
@ -228,9 +237,7 @@ bool upb_context_addfd(struct upb_context *c,
ref = resolve2(&c->symtab, &tmp, &e->e.key, fd->type_name, UPB_SYM_ENUM);
else
continue; /* No resolving necessary. */
upb_print(&e->e.key);
if(!ref.msg) { printf("FAILED!\n"); goto error; } /* Ref. to undefined symbol. */
printf("Successful!\n");
if(!ref.msg) goto error; /* Ref. to undefined symbol. */
upb_msg_ref(m, f, ref);
}
}
@ -240,6 +247,7 @@ bool upb_context_addfd(struct upb_context *c,
for(e = upb_strtable_begin(&tmp); e; e = upb_strtable_next(&tmp, &e->e))
upb_strtable_insert(&c->symtab, &e->e);
upb_strtable_free(&tmp);
return true;
error:

@ -16,7 +16,8 @@ static int div_round_up(int numerator, int denominator) {
}
static int compare_fields(const void *e1, const void *e2) {
const google_protobuf_FieldDescriptorProto *fd1 = e1, *fd2 = e2;
const google_protobuf_FieldDescriptorProto *fd1 = *(void**)e1;
const google_protobuf_FieldDescriptorProto *fd2 = *(void**)e2;
/* Required fields go before non-required. */
bool req1 = fd1->label == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REQUIRED;
bool req2 = fd2->label == GOOGLE_PROTOBUF_FIELDDESCRIPTORPROTO_LABEL_REQUIRED;
@ -90,6 +91,7 @@ void upb_msg_free(struct upb_msg *m)
upb_inttable_free(&m->fields_by_num);
upb_strtable_free(&m->fields_by_name);
free(m->fields);
free(m->field_descriptors);
}
void *upb_msg_new(struct upb_msg *m)

Loading…
Cancel
Save