diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-07-29 15:54:03 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-07-29 15:54:03 +0000 |
| commit | de9d7e4f3ccb1b199602c1a1ce884df37e54f834 (patch) | |
| tree | 7ecb990ffe55f28e5ce77a059c791f558e503130 /lib/command_graph.h | |
| parent | 76699ae7e0358c57a1186b88962d7233a7057d76 (diff) | |
lib: Cleanup some memory issues in CLI
Various memory leaks have been fixed and the quagga
memory macros are in use. Also consolidated the argv
and matching code into one graph traversal.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/command_graph.h')
| -rw-r--r-- | lib/command_graph.h | 46 |
1 files changed, 36 insertions, 10 deletions
diff --git a/lib/command_graph.h b/lib/command_graph.h index a9ffe0f7b6..dc78475ca6 100644 --- a/lib/command_graph.h +++ b/lib/command_graph.h @@ -35,6 +35,9 @@ struct graph_node struct cmd_element *element; /* used for passing arguments to command functions */ char *arg; + + /* refcount for node parents */ + int refs; }; /* @@ -47,7 +50,7 @@ struct graph_node * @param[in] child node * @return pointer to child if it is added, pointer to existing child otherwise */ -extern struct graph_node * +struct graph_node * add_node(struct graph_node *, struct graph_node *); /* @@ -61,7 +64,7 @@ add_node(struct graph_node *, struct graph_node *); * @param[in] second node to compare * @return 1 if equal, zero otherwise. */ -extern int +int cmp_node(struct graph_node *, struct graph_node *); /* @@ -71,17 +74,44 @@ cmp_node(struct graph_node *, struct graph_node *); * @param[in] node type * @return pointer to the newly allocated node */ -extern struct graph_node * +struct graph_node * new_node(enum graph_node_type); /** + * Copies a node. + * The children vector is copied, but the pointers the vector + * holds point to the same data as the original vector. + * The element, if it exists, is copied. + * + * @param[in] pointer to node to copy + * @return pointer to copied node + */ +struct graph_node * +copy_node(struct graph_node *); + +/** + * Frees the data associated with a graph_node. + * @param[out] pointer to graph_node to free + */ +void +free_node(struct graph_node *); + +/** + * Recursively calls free_node on a graph node + * and all its children. + * @param[out] graph to free + */ +void +free_graph(struct graph_node *); + +/** * Walks a command DFA, printing structure to stdout. * For debugging. * * @param[in] start node of graph to walk * @param[in] graph depth for recursion, caller passes 0 */ -extern void +void walk_graph(struct graph_node *, int); /** @@ -90,13 +120,9 @@ walk_graph(struct graph_node *, int); * @param[out] the buffer to write the description into * @return pointer to description string */ -extern char * +char * describe_node(struct graph_node *, char *, unsigned int); -/** - * Frees the data associated with a graph_node. - * @param[out] pointer to graph_node to free - */ void -free_node(struct graph_node *); +dump_node (struct graph_node *); #endif |
