Skip to content
Snippets Groups Projects
Commit f3b927f1 authored by Jake Drahos's avatar Jake Drahos
Browse files

Fixed memory leak in frontend_nodes

parent 4e43fda9
No related branches found
No related tags found
No related merge requests found
......@@ -11,14 +11,22 @@
*
* Returns 0 on success, 1 on error
*
* node_data and num_nodes are out-pointers.
* node_data must be a pointer to NULL
* num_nodes must be a pointer to zero
*
* Note : node_data may be resized inside this function.
* That is why you must pass in a strcut ... **
*/
int frontend_getnodes(
struct backend_conn * conn,
struct frontend_node_data ** node_data,
size_t * num_nodes) {
if ((node_data == NULL) || (num_nodes == NULL)) {
return 1;
}
if ((*node_data != NULL) || (*num_nodes != 0)) {
return 1;
}
char msg[64] = "";
int written;
......@@ -122,4 +130,14 @@ int frontend_addnode(
}
return 0;
}
\ No newline at end of file
}
void frontend_free_node_data(
struct frontend_node_data *nd,
size_t num_nodes)
{
for (size_t i = 0; i < num_nodes; i++) {
free(nd[i].name);
}
free(nd);
}
......@@ -8,8 +8,10 @@
*
* Returns 0 on success, 1 on error
*
* Note : node_data may be resized inside this function.
* That is why you must pass in a strcut ... **
* node_data and num_nodes are out pointers
* node_data must point to a NULL pointer
* num_nodes must point to zero
*
*/
int frontend_getnodes(
struct backend_conn * conn,
......@@ -25,4 +27,9 @@ int frontend_addnode(
struct backend_conn * conn,
struct frontend_node_data * node_data);
#endif /* __FRONTEND_NODES_H */
\ No newline at end of file
/* Free a node_data array */
void frontend_free_node_data(
struct frontend_node_data * nd,
size_t num_nodes);
#endif /* __FRONTEND_NODES_H */
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment