Visit Our UNIX and Linux User Community

glib detected: malloc() memory curruption

Thread Tools Search this Thread
Top Forums Programming glib detected: malloc() memory curruption
# 1  
Old 10-21-2011
glib detected: malloc() memory curruption

I am using libxml2 library for XMl parsing and libxml++ is C++ wrapper over that. So I am using API of libxml++. I am creating my class and composing instance xmlpp::Node *pNode in that. my class also have funciton prepareXPathQuery() which creates query string and have other fucntion fireXpathQuery which internallly calls pNode->find() function which returns sets of node which matches with fired query but when I fire query it gives error glib detected: malloc() memory curruption and prints backtrace.

/*implemntation of class */
#include "ConfigFileParser.hpp"
include "defines.hpp"
#include <libxml++/libxml++.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
class ConfigFileParser
std::string filePath;
xmlpp::DomParser parser;
xmlpp::Node *pNode;
char *query;
* Function Name : ConfigDataStructure
* @brief
* @param
* @return none
* @see
* Function Name : ~ConfigFileParser
* @brief destructor for class ConfigFileParser
* @param none
* @return none
* @see
* Function Name : prepareXpathQuery
* @brief prepere XPATH query to fire on XML file
* @param char *
* @param char *
* @param char *
* @param int depth=0
* @return void
* @see
void prepareXpathQuery(char *, char *, char *, int depth=0);
* Function Name : fireXpathQuery
* @brief It fires XPATH query on node
* @param node it's node on which query have to fire
* @return NodeSet it's the set of nodes foungd by query
* @see
xmlpp::NodeSet fireXpathQuery(xmlpp::Node *node = NULL);
filePath = XML_FILE_PATH;//XML file path is defined in defines.hpp
query = new char(MAX_QUERY_LENGTH);
pNode = parser.get_document()->get_root_node();
void ConfigFileParser::prepareXpathQuery(char *nodeName, char *attType, char *attName, int depth)
if(depth == 0)
xmlpp::NodeSet ConfigFileParser::fireXpathQuery(xmlpp::Node *node)
xmlpp::NodeSet set;
if(node != NULL)
set = node->find(query);
set = pNode->find(query);
return set;
int main()
int elementID;
int address;
char *text=NULL;
ConfigFileParser fileParser;
fileParser.prepareXpathQuery((char *)"Element", (char *)"type", (char *)"ModuleVoiceElem", 1);
xmlpp::NodeSet set = fileParser.fireXpathQuery();
xmlpp::Element *nodeElement = dynamic_cast<xmlpp::Element *>(*set.begin());
getBasicAttributes(elementID, address, text,nodeElement);

Moderator's Comments:
Mod Comment Please use code tags

when it run this program it gives error glib detected: malloc() memory curruption at highlighted line. Please help me. I dont know why this error comes.

Thanks in advance,
Sharad Wagh.

Last edited by jim mcnamara; 03-22-2012 at 11:14 PM..
# 2  
Old 10-21-2011
Not using code tags has destroyed all your indentation and filled your code with smilies. Please see the video tutorial on how to do so.

---------- Post updated at 09:26 AM ---------- Previous update was at 09:15 AM ----------

Instead of dynamic_cast, why not use the actual type set.begin() returns? After all, it might not be valid in all circumstances, and casting a 'no results' return into a pointer of the kind you wanted would probably crash.
# 3  
Old 03-22-2012

even i faced the same problem in linux.adding -lmcheck while linking in my make file helped me in finding what the exact problem is and rectifying the problem.

Previous Thread | Next Thread
Test Your Knowledge in Computers #642
Difficulty: Easy
The first full release of NeXTSTEP 1.0 shipped on September 18, 1988.
True or False?

10 More Discussions You Might Find Interesting

1. Solaris

No memory detected in Bank 3

Hi. Recently I discovered how to access the 'ok' prompt on my E450. (Thanks DukeNuke2) And so I've been running tests, checking the system out... (since until now I've not known how to get to the 'ok' prompt) And came across 0>INFO: No memory detected in Bank 3 and *** Missing DIMM(s)... as... (3 Replies)
Discussion started by: SomeoneTwo
3 Replies

2. Programming

*** glibc detected *** ./a.out malloc() memory corruption

I am facing a problem of memory corruption. The loop runs for the first time but does not go through the second time. What could be the problem? for(int z=0;z<2;z++) { fp=fopen("poly.dat","r"); /*do something which reads this file into a 2D array*/ fclose(fp); ... (10 Replies)
Discussion started by: dare
10 Replies

3. Programming

*** glibc detected *** : malloc(): memory corruption (fast)

Hi Friends, while executing the below code, am getting *** glibc detected *** ./ok: malloc(): memory corruption (fast) error, please suggest how to solve this issue. #include <stdio.h> #include <string.h> #include <sqlca.h> #include <alloca.h> /* Define constants for VARCHAR... (2 Replies)
Discussion started by: mpjobsrch
2 Replies

4. Programming

*** glibc detected *** ./a.out: malloc(): memory corruption (fast):

*** glibc detected *** ./a.out: malloc(): memory corruption (fast): Posted A minute ago M trying to make multiway tree and dont know what happend when this part of code get executed: 01void ins(NODE *ptr) 02{ 03 //working 04 if(ptr!=NULL) 05 { 06 SNODE *var=NULL; 07 var=(SNODE... (3 Replies)
Discussion started by: exgenome
3 Replies

5. Programming

./match_pattern.out: malloc(): memory corruption: 0x0000000013a11600 ***

Hi All, I have a simple code which does some computation by matching string patterns. In brief: 1. The code reads .dat and .txt files. 2. .dat files are huge text files and .txt files contain some important words. 3. I am just doing strstr to find the patterns. 4. The function returns the... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

6. Programming

Stress testing memory using malloc in linux ??

Hi to all, Recently i am testing an equipment that runs in i586 fedora linux. I have to test mmap function. For that i determined to fill the memory and run the required application to check whether it throws any mmap error regarding low resources. This is the line that does the allocation. ... (3 Replies)
Discussion started by: frozensmilz
3 Replies

7. Programming

Why does this occur? *** glibc detected *** malloc(): memory corruption: 0x10013ff8 ***

there seems not to be error in this segment. In some computers, it can work well. But in others, it will give a failure. why it ocurrs and how to deal with it? in a function: if( *ver == NULL ) { *ver = (vertex *) malloc(sizeof(vertex)); //this line ... (17 Replies)
Discussion started by: cdbug
17 Replies

8. Programming

Why memory allocated through malloc should be freed ?

Actually for a process to run it needs text, stack , heap and data segments. All these find a place in the physical memory. Out of these 4 only heap does exist after the termination of the process that created it. I want to know the exact reason why this happens. Also why the other process need to... (20 Replies)
Discussion started by: karthiktceit
20 Replies

9. Solaris

OS is not detected CPU and memory

Hi, Server AIBVRFCC failed POST while booting on 06/28/2009. Server is up, but OS cannot see two CPUs (CPU 0 and CPU 2) and half of the installed system memory (8 GB is physically installed but only 4 GB is seen by OS now). bld00016:root psrinfo 1 on-line since 06/28/09 05:51:36 3 on-line... (1 Reply)
Discussion started by: arumsun
1 Replies

10. Programming

malloc gives the same memory to two different nodes. How to deal with it?

When allocating memory for two different nodes, the resulting memory are the same. Clearly, this will lead to a mistake. This happened in a function. And the process must be in a function. (gdb) p tree->list $43 = (node *) 0x8be4180 (gdb) p tree->list $44 = (node *) 0x8be4180 At the... (2 Replies)
Discussion started by: cdbug
2 Replies

Featured Tech Videos