Make typedKey helpers more friendly to use
authorBenjamin Kaduk <kaduk@mit.edu>
Mon, 2 Mar 2015 21:05:51 +0000 (16:05 -0500)
committerBenjamin Kaduk <kaduk@mit.edu>
Fri, 25 Dec 2015 05:46:04 +0000 (00:46 -0500)
Make freeing a NULL key pointer a no-op.

Allow passing NULL to afsconf_typedKey_values() when not all
values are needed.

Change-Id: I3a4088747913e9e88be094da891cd2cca0cbb114
Reviewed-on: http://gerrit.openafs.org/11783
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Benjamin Kaduk <kaduk@mit.edu>

src/auth/keys.c

index 0ab3f29..54ad955 100644 (file)
@@ -1057,6 +1057,8 @@ afsconf_typedKey_new(afsconf_keyType type, int kvno, int subType,
 void
 afsconf_typedKey_free(struct afsconf_typedKey **key)
 {
+    if (*key == NULL)
+       return;
     rx_opaque_freeContents(&(*key)->key);
     free(*key);
     *key = NULL;
@@ -1082,10 +1084,14 @@ void
 afsconf_typedKey_values(struct afsconf_typedKey *key, afsconf_keyType *type,
                        int *kvno, int *subType, struct rx_opaque **material)
 {
-    *type = key->type;
-    *kvno = key->kvno;
-    *subType = key->subType;
-    *material = &key->key;
+    if (type != NULL)
+       *type = key->type;
+    if (kvno != NULL)
+       *kvno = key->kvno;
+    if (subType != NULL)
+       *subType = key->subType;
+    if (material != NULL)
+       *material = &key->key;
 }
 
 int