help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: g++ usage of new generates a segmentation fault


From: Paul Pluzhnikov
Subject: Re: g++ usage of new generates a segmentation fault
Date: Wed, 12 Jul 2006 20:35:48 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) XEmacs/21.4 (Jumbo Shrimp, linux)

"Christophe Limbrée" <christophelimbree@hotmail.com> writes:

[Please do not top-post.]

> I didn't free all variables allocated with new because I thought that
> the program termination woud free them for me.

That's correct, but it is "cleaner" to delete dynamic storage,
because:
- it makes analysis with leak checkers (such as valgrind) easier, and
- you never know when you'll want to reuse this code in a loop, and
  if the code doesn't do cleanup, you'll run out of memory really fast.

> Obviously that could cause my problem.

No, it can't. *Not* freeing the memory will never cause a segfault
(but it can cause abort if the allocator runs out of memory).

> As I am rewriting a c program, I am adding c++ code
> step by step into my source code. c and c++ are mixed into my code. I
> read somewhere that I could get conflict. Is it right?

Wrong. Mixing C and C++ is perfectly safe, and does not *in itself*
cause any segfaults.

You have a bug, and valgrind will likely show it to you immediately,
so why don't you stop wasting time hypothesisizing what the problem
might be, and use proper tools to find it.

Cheers,
-- 
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]