libxml C fun

Mark Ellis mark.uzumati at virgin.net
Mon Dec 2 07:34:25 PST 2002


On 2002.12.02 14:13 Billy O'Connor wrote:
> mark.uzumati at virgin.net (Mark Ellis) writes:
> 
> > Mostly a question for Neven I guess, but anyone else that has any
> > ideas please pitch in.
> >
> > Neven, im playing with libxml2 in C, mostly just to get me back up
> to
> > speed with something besides perl, and i'm having a pig of a time
> with
> > xmlParseMemory, blasted thing keeps segfaulting. To me it looks as
> > simple as passing the xml string and size. Have you ever had
> problems
> > ? I dont think i need to initialize anything to use this function
> but
> > maybe i'm missing something ?
> >
> 
> I'm doing the same thing, Mark, can you post a small example and the
> compiler flags?
> 

Snippets are tricky since its all tied in together and using libtool,
but basically

gcc -g -O2 -o simplealfs -static simplealfs-simplealfs.o  -L/usr/lib 
/usr/lib/libxml2.a -lz -lpthread -lm ../libalfs/.libs/libalfs.a -ldl


cut from simplealfs.c

         char *xml = NULL;
         xmlDocPtr xmldoc = NULL;

/* reads a file and stores it all in a string */
         xml = read_profile(profile);
	if (xml == NULL) {
                 return 0;
	}

         profile_len = strlen(xml)+1;

         if ((xmldoc = xmlParseMemory(xml, profile_len)) == NULL) {
                 XFREE(xmlstr);
                 fprintf(stderr, "Profile parse error : %s\n", profile);
                 return 0;
         }


Program received signal SIGSEGV, Segmentation fault.
chunk_alloc (ar_ptr=0x815e4c0, nb=4008) at malloc.c:3075
3075	malloc.c: No such file or directory.
	in malloc.c
(gdb) bt
#0  chunk_alloc (ar_ptr=0x815e4c0, nb=4008) at malloc.c:3075
#1  0x080ea80d in __libc_malloc (bytes=2054489645) at malloc.c:2810
#2  0x0805f456 in xmlBufferCreate () at tree.c:5486
#3  0x0806464e in xmlAllocParserInputBuffer (enc=135682632) at 
xmlIO.c:1567
#4  0x08064e0c in xmlParserInputBufferCreateMem (mem=0xfa8 <Address 
0xfa8 out of bounds>, size=135652544,     enc=135682632) at xmlIO.c:2015
#5  0x080596c2 in xmlCreateMemoryParserCtxt (buffer=0x815e4c0 "", 
size=135652544) at parser.c:10485
#6  0x08059757 in xmlSAXParseMemoryWithData (sax=0x815e4c0, 
buffer=0x8165a48 "", size=135682632,     recovery=0, data=0xfa8) at 
parser.c:10533
#7  0x0805980e in xmlSAXParseMemory (sax=0x8165a48, buffer=0x8165a48 
"", size=135682632, recovery=135682632)
     at parser.c:10576
#8  0x08059848 in xmlParseMemory (buffer=0x8165a48 "", size=135682632) 
at parser.c:10590
#9  0x0804857e in load_profile (profile=0xbffffcbc "mozilla.xml", 
num_profiles=0x815e4c0)
     at simplealfs.c:201
#10 0x08048762 in get_options (argc=2, argv=0xbffffba4) at 
simplealfs.c:306
#11 0x08048254 in main (argc=135682632, argv=0x815e4c0) at 
simplealfs.c:61
#12 0x080cda97 in __libc_start_main (main=0x80481f0 <main>, 
argc=135652544, ubp_av=0xfa8,     init=0x80480b4 <_init>, 
fini=0x8126520 <_fini>, rtld_fini=0, stack_end=0x8165a48)
     at ../sysdeps/generic/libc-start.c:129



Hmm thats wierd, i keep getting different results. Before the call
to xmlParseMemory, xml points to a valid string that contains the
profile, whereas after the segfault xml doesnt contain said string.
I'm sure thats different from last time. I'm a bit rusty with C but
i cant see where i could be going wrong.

Mark
-- 
Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe alfs-discuss' in the subject header of the message



More information about the alfs-discuss mailing list