I'm a beginner in C programming, and I'm sure this question is done and solved, but I cannot find much of an answer looking around. In my program, I have this implementation of a BST (Binary Search Tree) node:
typedef struct bstnode{
char *key;
void *value;
struct bstnode *left;
struct bstnode *right;
}bstnode;
In which I need value to be void* to utilize this same structure for different purposes. My fear, however, is that in doing so I am allowing for more possibilities of error and insability in my program. For example: in many cases, key points to a value that lives in the stack. Which is, well, fine. However, sometimes I need to perform dynamic allocation for key. And sometimes, value is also dynamically allocated. Which means that for every tree I create, I have to perform different deallocation routines (and, if the value is another dynamically allocated struct, I also need to make sure to deallocate that struct properly). Of course, I can keep track of which structure is which, but I fear that this might get out of hand and lead to memory leaks, and also to a less "mantainable" codebase (ex. having to make specific deallocation functions for specific use cases). My question is: is what I am doing bad practice? Is there a better way to go about it than having to write functions for every use case of the structure?