Skip to content
Snippets Groups Projects
Commit b7e65d96 authored by Pradeep Varma, A. (Adithya, Student M-CS)'s avatar Pradeep Varma, A. (Adithya, Student M-CS)
Browse files

add malloc memory check in tree_insert()

parent 8057d7fc
No related branches found
No related tags found
1 merge request!1Assignment
......@@ -98,6 +98,10 @@ void node_insert(Node* node, int age, char* name) {
void tree_insert(Tree* tree, int age, char* name) {
if (tree->root == NULL) {
Node *node = malloc(sizeof(Node));
if (node == NULL) {
perror("Failed to allocate memory for new node");
exit(EXIT_FAILURE);
}
node->name = name;
node->left = NULL;
node->right = NULL;
......
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