linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Bambach <eric@cisu.net>
To: Ankit Jain <ankitjain1580@yahoo.com>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: malloc and free
Date: Fri, 24 Dec 2004 12:52:36 -0600	[thread overview]
Message-ID: <200412241252.36261.eric@cisu.net> (raw)
In-Reply-To: <20041224183913.9579.qmail@web52907.mail.yahoo.com>

On Friday 24 December 2004 12:39 pm, you wrote:
> hi
>
> routine xyz uses malloc and free functions. it gives
> accurate and correct result if called once.
>
> but if the function is called in a loop N number of
> times then probably it gives segmentation fault.
>
> what is the reason?  can any body guess or test code
> is needed?
>
> thanks
>
> ankit jain

A common cause of failure in the malloc/free routines is memory corruption. 
The trick about memory corruption and buffer overflows is that they work 
sometimes/most of the time. Perhaps you are doing out-of-bounds reading or 
(gak!) writing with the memory. Try running it under valgrind to see if this 
is the case.

Also, although routine xyz may not corrupt the memory perhaps something else 
in your program is? Writing in strange places confuses libc and can result in 
a segfault in places that can be quite far away from the original spot of 
corruption.

----------------------------------------
--EB

> All is fine except that I can reliably "oops" it simply by trying to read
> from /proc/apm (e.g. cat /proc/apm).
> oops output and ksymoops-2.3.4 output is attached.
> Is there anything else I can contribute?

The latitude and longtitude of the bios writers current position, and
a ballistic missile.

                --Alan Cox LKML-December 08,2000 

----------------------------------------
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2004-12-24 18:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-24 18:39 malloc and free Ankit Jain
2004-12-24 18:52 ` Eric Bambach [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-05-20 11:26 Sameer Maggon
2002-05-20 10:06 ` wwp
2002-05-20 18:16 ` Andrew Edmondson
2002-05-20  9:55 Alvarez Alberto-AALVARB1

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200412241252.36261.eric@cisu.net \
    --to=eric@cisu.net \
    --cc=ankitjain1580@yahoo.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).