[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bison and malloc
From: |
s88 |
Subject: |
Re: bison and malloc |
Date: |
Wed, 11 Oct 2006 21:58:58 +0800 |
On 10/11/06, Tim Van Holder <address@hidden> wrote:
s88 wrote:
> Hi all:
> I'm confused with the bison and malloc right now...
> I'm using the Bison 2.0 on Ubuntu(Linux) 6.06, and everytime when I use
> the malloc(actually is strdup) in the production rules. It will cause an
> unpredictable
> segmentation fault. The stack size on my system is set unlimited.
> Every time after using the dynamic allocate memory, I'll free the memory
by
> myself.
>
> What cause this fault, and how to fix it?
>
> Any idea?
>
> Thankx!!!!!
> Dave.
The most likely cause would be that you're free()ing twice.
But without a little bit of code to illustrate what you're doing, it's
very hard to diagnose a crash bug.
well..thank U all first!!
Let me show my code here...
I want to parse the sequence such likes X1,X2,{Y1,X4,Z5}
BTW, I'm using the GTK library to malloc and free, but I'm sure the question
is not on the GTK.
arguements : arguement{
$$ = $1;
}| arguements ',' arguement{
GList *_l = g_list_concat($1,$3);
$$ = _l;
};
arguement:'{' arguements '}' {
$$ = $2;
}|'[' arguements ']' {
$$ = $2;
}|UID{
$$ = create_arglist($1);
}|ID{
$$ = create_arglist($1);
}|INTEGER{
}|EUINT64VAL{
};
#include <gtk/gtk.h>
GList* create_arglist(const gchar* str){
GList* _list = NULL;
gchar* _str = g_strdup(str);
_list = g_list_append(_list,_str);
return _list;
}
void arglist_free(GList* list){
GList *_cur = list;
GList *_next;
while(_cur !=NULL){
_next = _cur->next;
g_free(_cur->data);
_cur = _next;
}
g_list_free(list);
Dave.
--
System on Chip Design Lab.
Dept. of Computer Science and Information Engineering,
National Chung Cheng University
E-mail : address@hidden