summaryrefslogtreecommitdiff
path: root/src/upb_mm.c
diff options
context:
space:
mode:
authorJoshua Haberman <joshua@reverberate.org>2009-09-26 11:46:38 -0700
committerJoshua Haberman <joshua@reverberate.org>2009-09-26 11:46:38 -0700
commit33a68acb14759cb6fcf796b41ad001c93de4b8e4 (patch)
treef03543b04c0e5b7ce7f2650ff1330919d4d6e055 /src/upb_mm.c
parent4b47002198f2c0404e16d2f02786845d6d3a0d3b (diff)
Use a status object for errors so a message can be returned.
Also delay deletion of subfields until the entire message is deleted.
Diffstat (limited to 'src/upb_mm.c')
-rw-r--r--src/upb_mm.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/upb_mm.c b/src/upb_mm.c
index bdf5f08..6f9a028 100644
--- a/src/upb_mm.c
+++ b/src/upb_mm.c
@@ -9,14 +9,20 @@
#include "upb_array.h"
#include "upb_msg.h"
+static void upb_mm_destroy(union upb_value_ptr p, upb_mm_ptrtype type)
+{
+ if(*p.msg) {
+ union upb_mmptr mmptr = upb_mmptr_read(p, type);
+ upb_mm_unref(mmptr, type);
+ }
+}
+
void upb_msg_destroy(struct upb_msg *msg) {
uint32_t i;
for(i = 0; i < msg->def->num_fields; i++) {
struct upb_msg_fielddef *f = &msg->def->fields[i];
if(!upb_msg_isset(msg, f) || !upb_field_ismm(f)) continue;
- upb_mm_ptrtype type = upb_field_ptrtype(f);
- union upb_mmptr mmptr = upb_mmptr_read(upb_msg_getptr(msg, f), type);
- upb_mm_unref(mmptr, type);
+ upb_mm_destroy(upb_msg_getptr(msg, f), upb_field_ptrtype(f));
}
free(msg);
}
@@ -26,11 +32,9 @@ void upb_array_destroy(struct upb_array *arr)
if(upb_elem_ismm(arr->fielddef)) {
upb_arraylen_t i;
/* Unref elements. */
- for(i = 0; i < arr->len; i++) {
+ for(i = 0; i < arr->size; i++) {
union upb_value_ptr p = upb_array_getelementptr(arr, i);
- upb_mm_ptrtype type = upb_elem_ptrtype(arr->fielddef);
- union upb_mmptr mmptr = upb_mmptr_read(p, type);
- upb_mm_unref(mmptr, type);
+ upb_mm_destroy(p, upb_elem_ptrtype(arr->fielddef));
}
}
if(arr->size != 0) free(arr->elements._void);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback