After two days of working on this bug, I just got it working but I don't know why. I'm throwing this out there in hopes someone recognizes it but I think everyone will say it doesn't make sense.
The code is for a simple xml parser. I find the xml file size, malloc that size and fread the xml. Close the file and scan the xml in memory, creating a linked list/tree structure, malloc'ing for more memory as more nodes are created. Each node is a struct that contains a pointer the next/previous node, element name, attributes, etc. There are typically less than 50 nodes in each file.
Each node gets its own malloc'ed memory space and all that data is copied into each node/struct from the xml file. After parsing, I free the xml data in memory while keeping pointer to the root node. The root node is returned to the calling program which then searches for whatever node/elements it needs.
What's thrown me for a loop is freeing the memory for the initial fread xml file causes the program to lose or change some of the pointers. And this only happens on my remote web server (Apache on CentOS), not locally in a test program that does the same thing. If I don't free the memory, it works everywhere but nothing points to that memory after it returns!
I know someone's going to say, "need to see the code" but, as I said, I just now finished this and I'd have to think of a way to simplify things to show a test case and I need to go take a walk. For the moment I hope this clicks with someone for when I get back.
The code is for a simple xml parser. I find the xml file size, malloc that size and fread the xml. Close the file and scan the xml in memory, creating a linked list/tree structure, malloc'ing for more memory as more nodes are created. Each node is a struct that contains a pointer the next/previous node, element name, attributes, etc. There are typically less than 50 nodes in each file.
Each node gets its own malloc'ed memory space and all that data is copied into each node/struct from the xml file. After parsing, I free the xml data in memory while keeping pointer to the root node. The root node is returned to the calling program which then searches for whatever node/elements it needs.
What's thrown me for a loop is freeing the memory for the initial fread xml file causes the program to lose or change some of the pointers. And this only happens on my remote web server (Apache on CentOS), not locally in a test program that does the same thing. If I don't free the memory, it works everywhere but nothing points to that memory after it returns!
I know someone's going to say, "need to see the code" but, as I said, I just now finished this and I'd have to think of a way to simplify things to show a test case and I need to go take a walk. For the moment I hope this clicks with someone for when I get back.
Comment