Fix unintentional free of the last value when adding a new value to a key.
authorWilco Baan Hofman <wilco@baanhofman.nl>
Tue, 19 Jan 2010 11:06:01 +0000 (12:06 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Tue, 19 Jan 2010 20:59:18 +0000 (09:59 +1300)
Signed-off-by: Jelmer Vernooij <jelmer@samba.org>
source4/lib/registry/regf.c

index a7fed4205403d3725ef5ee49357105fc357bb7e0..a96c7db0eeed8edd70da891c2b57bf29466f2606 100644 (file)
@@ -1791,11 +1791,9 @@ static WERROR regf_set_value(struct hive_key *key, const char *name,
                                break;
                        }
                }
-               /* Free data, if any */
-               if (!(vk.data_length & 0x80000000)) {
-                       hbin_free(regf, vk.data_offset);
-               }
        }
+
+       /* If it's new, create the vk struct, if it's old, free the old data. */
        if (old_vk_offset == -1) {
                vk.header = "vk";
                vk.name_length = strlen(name);
@@ -1806,7 +1804,13 @@ static WERROR regf_set_value(struct hive_key *key, const char *name,
                        vk.data_name = NULL;
                        vk.flag = 0;
                }
+       } else {
+               /* Free data, if any */
+               if (!(vk.data_length & 0x80000000)) {
+                       hbin_free(regf, vk.data_offset);
+               }
        }
+
        /* Set the type and data */
        vk.data_length = data.length;
        vk.data_type = type;