]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
marshal: serialization may return 0 and target untouched
authorVincent Bernat <bernat@luffy.cx>
Sun, 13 Jan 2013 10:25:39 +0000 (11:25 +0100)
committerVincent Bernat <bernat@luffy.cx>
Sun, 13 Jan 2013 10:25:39 +0000 (11:25 +0100)
If serialization finds a structure already serialized, it skips it and
return 0. `target` should not be freed.

src/marshal.c

index 251a2b50386161c8990f9ec430cd1a5df818487f..011e9cb64ae9845a2fc97d17d7e544bb794c7580 100644 (file)
@@ -141,13 +141,13 @@ marshal_serialize_(struct marshal_info *mi, void *unserialized, void **input,
                        source = (void *)((unsigned char *)unserialized + current->offset);
                if (current->offset2)
                        memcpy(&osize, (unsigned char*)unserialized + current->offset2, sizeof(int));
+               target = NULL;
                sublen = marshal_serialize_(current->mi,
                    source, &target,
                    current->kind == substruct, refs, osize);
-               if (sublen == -1 || target == NULL) {
+               if (sublen == -1) {
                        log_warnx("marshal", "unable to serialize substructure %s for %s",
                            current->mi->name, mi->name);
-                       free(target);
                        free(serialized);
                        return -1;
                }