Thanks for giving me so many hints! I checked every possible problem as
you guys have suggested and fixed a few bugs. But it still gets segfault,
which is over my head...
I installed valgrind. The error message I got is as follows:
-----------------------------------------
Conditional jump or move depends on uninitialised value(s)
==1200== at 0x8114324: INSIGNIA::local_bw_monitor(Packet*)
(insignia.cc:781)
==1200== by 0x8112E7B: INSIGNIA::tap(Packet const*) (insignia.cc:242)
==1200== by 0x80FAA31: Mac802_11::recv_timer() (in
/usr/ns-allinone-2.26/ns-2.26/ns)
==1200== by 0x80F89CE: Mac802_11::recvHandler() (in
/usr/ns-allinone-2.26/ns-2.26/ns)
==1200==
==1200== Invalid read of size 4
==1200== at 0x806AA44: PacketQueue::head() (in
/usr/ns-allinone-2.26/ns-2.26/ns)
==1200== by 0x8138CA3: AODV::rt_ll_failed(Packet*) (in
/usr/ns-allinone-2.26/ns-2.26/ns)
==1200== by 0x8138AED: aodv_rt_failed_callback(Packet*, void*) (in
/usr/ns-allinone-2.26/ns-2.26/ns)
==1200== by 0x80FA17D: Mac802_11::RetransmitRTS() (in
/usr/ns-allinone-2.26/ns-2.26/ns)
==1200== Address 0x10 is not stack'd, malloc'd or free'd
Segmentation fault
----------------------------
I guess it is the last one that causes the segfault. I don't why it gets
to read from some wrong address? After I run this program, some of
applications of my Redhat (9.0) is not working right.
Could you give me a hint what can cause this kind of error? I can't figure
out how to fix this.
Thanks a million!
Bin Lu
On Fri, 3 Oct 2003, Erik de Castro Lopo wrote:
[color=blue]
> Bin Lu wrote:[color=green]
> >
> > I keep getting this malloc problem when my program tries to allocate
> > memory for some pointer. The statement is like:
> >
> > rsv_cache = (rsvcache *) malloc (sizeof(rsvcache));[/color]
>
> As others have said, don't cast the return of malloc.
>[color=green]
> > It goes through the function with this statement several times and seems
> > that it has successfully allocated the memory. and then at some
> > iteration, it just gets this segmentation fault.[/color]
>
> This is almost certain, your program corrupting heap memory. There
> are probably 100 ways to do this, including writing past the end of
> a buffer, incorrect array indexing and so on.
>
> I notice that you are posting this using Pine and using gdb
> for debugging. This means that there is also some chance that
> you are running Linux. If that is the case, search
>
http://freshmeat.net/ for a program called valgrind (only
> works on i386 Linux unfortunately) which is really good at
> finding bugs like this.
>
> Erik
> --
> +-----------------------------------------------------------+
> Erik de Castro Lopo
nospam@mega-nerd.com (Yes it's valid)
> +-----------------------------------------------------------+
> "One of the great things about books is sometimes there are
> some fantastic pictures" - George W. Bush
>[/color]