Re: memory leak (definition?)



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.
.




Relevant Pages

  • kernel vm question
    ... static int test_modevent ... is the full kernel module source and a dmesg of the hardware in question. ... CPU: IntelXeonCPU 2.66GHz ... pci0: <PCI bus> on pcib0 ...
    (freebsd-hackers)
  • Re: WAV file question
    ... >> matches the endianness of the file. ... > couldn't read a .wav file properly? ... The Google Groups interface makes proper followups needlessly ... by fwriteing, say, an int value, then copy the file to a big-endian ...
    (comp.lang.c)
  • Juju
    ... I only looked briefly at SBP-2, and at submit/callback paths it pulled, ... please implement proper ORB cancellation. ... int function, int lun, void *response) ...
    (Linux-Kernel)
  • some /proc understandings
    ... struct proc_dir_entry *myfile_file; ... off, int count, int *eof, void *data) ... from another kernel module?? ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • kernel module function arguments
    ... I am experimenting a kernel module: ... static int dummy_init{ ... // USERSPACE CODE START ... As a result my kernel module intercept vsyscall call (calling ...
    (comp.os.linux.development.system)