]> code.citadel.org Git - citadel.git/blobdiff - citadel/modules/openid/serv_openid_rp.c
Fixed a double free error in serv_openid_rp.c
[citadel.git] / citadel / modules / openid / serv_openid_rp.c
index 2f8de996827756e6b603882fb76bdee1c30d1ef9..bd883bf31e4b6110463879a2218a8aa0eaeca3d0 100644 (file)
@@ -67,6 +67,7 @@ struct ctdl_openid {
  */
 
 
+
 /*
  * Attach an OpenID to a Citadel account
  */
@@ -120,18 +121,39 @@ int attach_openid(struct ctdluser *who, char *claimed_id)
  */
 void openid_purge(struct ctdluser *usbuf) {
        struct cdbdata *cdboi;
+       HashList *keys = NULL;
+       HashPos *HashPos;
+       char *deleteme = NULL;
+       long len;
+       void *Value;
+       char *Key;
+
+       keys = NewHash(1, NULL);
+       if (!keys) return;
+
 
        cdb_rewind(CDB_OPENID);
        while (cdboi = cdb_next_item(CDB_OPENID), cdboi != NULL) {
                if (cdboi->len > sizeof(long)) {
                        if (((long)*(cdboi->ptr)) == usbuf->usernum) {
-                               CtdlLogPrintf(CTDL_DEBUG, "FIXME we have to delete an openid\n");
+                               deleteme = strdup(cdboi->ptr + sizeof(long)),
+                               Put(keys, deleteme, strlen(deleteme), deleteme, generic_free_handler);
                        }
                }
                cdb_free(cdboi);
        }
 
-       /* FIXME finish this */
+       /* Go through the hash list, deleting keys we stored in it */
+
+       HashPos = GetNewHashPos();
+       while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0)
+       {
+               CtdlLogPrintf(CTDL_DEBUG, "Deleting associated OpenID <%s>\n", Value);
+               cdb_delete(CDB_OPENID, Value, strlen(Value));
+               /* note: don't free(Value) -- deleting the hash list will handle this for us */
+       }
+       DeleteHashPos(&HashPos);
+       DeleteHash(&keys);
 }
 
 
@@ -469,12 +491,6 @@ void cmd_oids(char *argbuf) {
 
 
 
-/*
- * Callback function to free a pointer (used below in the hash list)
- */
-void free_oid_key(void *ptr) {
-       free(ptr);
-}
 
 
 /*
@@ -485,7 +501,6 @@ void cmd_oidf(char *argbuf) {
        char thiskey[1024];
        char thisdata[1024];
        HashList *keys = NULL;
-       HashPos *HashPos;
        struct ctdl_openid *oiddata = (struct ctdl_openid *) CC->openid_data;
 
        keys = NewHash(1, NULL);
@@ -500,7 +515,7 @@ void cmd_oidf(char *argbuf) {
                extract_token(thiskey, buf, 0, '|', sizeof thiskey);
                extract_token(thisdata, buf, 1, '|', sizeof thisdata);
                CtdlLogPrintf(CTDL_DEBUG, "%s: [%d] %s\n", thiskey, strlen(thisdata), thisdata);
-               Put(keys, thiskey, strlen(thiskey), strdup(thisdata), free_oid_key);
+               Put(keys, thiskey, strlen(thiskey), strdup(thisdata), generic_free_handler);
        }
 
 
@@ -646,17 +661,21 @@ void cmd_oidf(char *argbuf) {
        }
        cprintf("000\n");
 
-       /* Free the hash list */
+       /*
+        * We will eventually do something with the data in the hash list.
+        *
        long len;
        void *Value;
        char *Key;
-
+       HashPos *HashPos;
        HashPos = GetNewHashPos();
        while (GetNextHashPos(keys, HashPos, &len, &Key, &Value)!=0)
        {
-               free(Value);
        }
        DeleteHashPos(&HashPos);
+        */
+
+       DeleteHash(&keys);              /* This will free() all the key data for us */
 }