Re: memory leak (definition?)
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Wed, 28 Dec 2005 00:14:41 +0000
bill wrote:
Does the following constitute a memory leak?
#include <stdlib.h>
malloc *requires* a correct declaration in scope because it does not return an int, which is what the compiler will assume. On some systems ints and pointers are returned in different registers and in others int is smaller than a pointer, so it is not just a theoretical possibility for it to go wrong without the declaration, but a very real situation on modern hardware.
int
main(int ac, char **av)
{
char *buf;
while(1) {
buf = malloc(BIG_NUMBER);
execv(av[0], av);
execv is not a stnadard function, so we have no idea what it will do.
}}
The question is motivated by the following scenario: I am using a 3rd party kernel module that I really do not trust, and it exhibits strange behavior when I use their free functions. Rather than trying to figure out the proper usage of their library
Uh oh. That is an extremely dangerous approach to take. If you don't understand how to use it properly then you are almost certain to get in to all sorts of trouble. You should take the time and effort to learn it properly rather than try to hack around what you don't understand.
<OT> Also, kernel modules and libraries are normally rather different things. </OT>
and do things like while(1) { do_stuff(); /* should only return on error*/ clean_up(); }
I was thinking of replacing clean_up() with an exec call. (Currently, the loop gets into a state that is clearly unhappy, and killing the process and restarting a new instance works to resolve the errors). Would replacing clean_up() with execv() be equivalent to killing the process and restarting a new instance?
Ask on a group where execv is topical, such as comp.unix.programmer, although you should read their FAQ and a few days postings first.
> or will I just be masking a bigger
problem? Clearly, the correct solution is to stop using this kernel module, but that is unfortunately out of my hands.
The correct solution is to understand the SW you are using and how to use it correctly. It is IMHO far more likely to be a problem in your code than the code you are calling.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
.
- Follow-Ups:
- Re: memory leak (definition?)
- From: Christopher Benson-Manica
- Re: memory leak (definition?)
- References:
- memory leak (definition?)
- From: bill
- memory leak (definition?)
- Prev by Date: Re: gets() - dangerous?
- Next by Date: Re: confused about behaviour of scanf
- Previous by thread: Re: memory leak (definition?)
- Next by thread: Re: memory leak (definition?)
- Index(es):
Relevant Pages
|
|