* prof_tree.c (profile_node_iterator): Added comments indicating that
authorTheodore Tso <tytso@mit.edu>
Mon, 25 Jan 1999 23:47:01 +0000 (23:47 +0000)
committerTheodore Tso <tytso@mit.edu>
Mon, 25 Jan 1999 23:47:01 +0000 (23:47 +0000)
profile_node_iterator, not being an exported interface, returns
pointers into the parse tree, and that values should be strdup()'ed
before returning them to a calling application.

prof_get.c (profile_iterator): Strdup the name and value strings
before returning them to the calling application.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@11124 dc483132-0cff-0310-8789-dd5450dbe970

src/util/profile/prof_get.c
src/util/profile/prof_tree.c

index ff07bc3ef2774e36a4c6bd1ff25b3d125fd82674..094c6a8d3cafdf561874f39caa38f20477031b25 100644 (file)
@@ -364,7 +364,37 @@ errcode_t profile_iterator(iter_p, ret_name, ret_value)
        void    **iter_p;
        char **ret_name, **ret_value;
 {
-       return profile_node_iterator(iter_p, 0, ret_name, ret_value);
+       char *name, *value;
+       errcode_t       retval;
+       
+       retval = profile_node_iterator(iter_p, 0, &name, &value);
+       if (retval)
+               return retval;
+
+       if (ret_name) {
+               if (name) {
+                       *ret_name = malloc(strlen(name)+1);
+                       if (!*ret_name)
+                               return ENOMEM;
+                       strcpy(*ret_name, name);
+               } else
+                       *ret_name = 0;
+       }
+       if (ret_value) {
+               if (value) {
+                       *ret_value = malloc(strlen(value)+1);
+                       if (!*ret_value) {
+                               if (ret_name) {
+                                       free(*ret_name);
+                                       *ret_name = 0;
+                               }
+                               return ENOMEM;
+                       }
+                       strcpy(*ret_value, value);
+               } else
+                       *ret_value = 0;
+       }
+       return 0;
 }
 
 void profile_release_string(str)
index e8257c826fe28be12dc9483c0afbed8d956737d5..499296c74add3a71782c62316a1b1727a1d6b99d 100644 (file)
@@ -206,7 +206,7 @@ int profile_is_node_final(node)
  *
  * The returned character string in value points to the stored
  * character string in the parse string.  Before this string value is
- * returned to a calling application (profile_find_node_relatioon is not an
+ * returned to a calling application (profile_find_node_relation is not an
  * exported interface), it should be strdup()'ed.
  */
 errcode_t profile_find_node_relation(section, name, state, ret_name, value)
@@ -430,6 +430,13 @@ void profile_node_iterator_free(iter_p)
        *iter_p = 0;
 }
 
+/*
+ * Note: the returned character strings in ret_name and ret_value
+ * points to the stored character string in the parse string.  Before
+ * this string value is returned to a calling application
+ * (profile_node_iterator is not an exported interface), it should be
+ * strdup()'ed.
+ */
 errcode_t profile_node_iterator(iter_p, ret_node, ret_name, ret_value)
        void    **iter_p;
        struct profile_node     **ret_node;