Major and incompatible overhaul of key_data representation. Fix leaks.
[u/mdw/catacomb] / key-fetch.c
index d80382f..e28b9b2 100644 (file)
@@ -80,8 +80,9 @@ key_packdef *key_fetchinit(const key_fetchdef *kf,
 
   /* --- Fill in the top part --- */
 
-  kp->kp.kd.e = KENC_STRUCT;
+  kp->kp.e = KENC_STRUCT;
   kp->kp.p = &kp[1];
+  kp->kp.kd = 0;
   kpd = &kp->kp;
 
   /* --- Initialize for the main loop --- */
@@ -107,7 +108,8 @@ key_packdef *key_fetchinit(const key_fetchdef *kf,
 
     while (kf->name) {
       kp->name = kf->name;
-      kp->kp.kd.e = kf->e;
+      kp->kp.e = kf->e;
+      kp->kp.kd = 0;
       if ((kf->e & KF_ENCMASK) != KENC_STRUCT)
        kp->kp.p = cp + kf->off;
       else {
@@ -153,7 +155,7 @@ int key_fetch(key_packdef *kp, key *k)
   int e;
 
   key_fulltag(k, &d);
-  e = key_unpack(kp, &k->k, &d);
+  e = key_unpack(kp, k->k, &d);
   dstr_destroy(&d);
   return (e);
 }
@@ -173,13 +175,13 @@ int key_fetch(key_packdef *kp, key *k)
 int key_fetchbyname(key_packdef *kp, key_file *kf, const char *tag)
 {
   dstr d = DSTR_INIT;
-  key_data *kd;
+  key_data **kd;
   int e;
 
   if (key_qtag(kf, tag, &d, 0, &kd))
     e = KERR_NOTFOUND;
   else
-    e = key_unpack(kp, kd, &d);
+    e = key_unpack(kp, *kd, &d);
   dstr_destroy(&d);
   return (e);
 }
@@ -196,8 +198,8 @@ int key_fetchbyname(key_packdef *kp, key_file *kf, const char *tag)
 
 void key_fetchdone(key_packdef *kp)
 {
-  key_packstruct *kps = (key_packstruct *)(((char *)kp) -
-                                          offsetof(key_packstruct, kp));
+  key_packstruct *kps =
+    (key_packstruct *)(((char *)kp) - offsetof(key_packstruct, kp));
   key_unpackdone(kp);
   if (kps->name)
     xfree(kps);