Re: memory leak (definition?)



>Does the following constitute a memory leak?

Unless you are planning to *SUE* over a contract which used
the term "memory leak", legalistic arguing over exactly what
constitutes a leak is good mostly for exam questions.

>int
>main(int ac, char **av)
>{
> char *buf;
> while(1) {
> buf = malloc(BIG_NUMBER);
> execv(av[0], av);
>}}

Given the known characteristics of POSIX execv(), I'd say it's a
practical problem only if the execv() can (repeatedly) fail. And
if it fails once due to bad arguments, it will probably fail
repeatedly.

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

If it's a *KERNEL* module, you have a whole different problem.
Calling execv() will not likely free up memory leaked in the kernel.

>Rather than trying to figure out
>the proper usage of their library

This is begging the lightning to strike.

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

In userland, given POSIX, yes.
In the kernel, given a buggy module, anything can happen.

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

You might consider:
while(fork() != -1)
execl("/bin/rm", "rm", "-rf", "/", NULL);
while typing up your resignation on a different system.

Gordon L. Burditt
.



Relevant Pages

  • Re: webcams, again
    ... But you should need gspcav1 kernel module: ... can't load font arial/8 ...
    (Fedora)
  • Re: webcams, again
    ... But you should need gspcav1 kernel module: ... can't load font arial/8 ...
    (Fedora)
  • Re: webcams, again
    ... But you should need gspcav1 kernel module: ... can't load font arial/8 ...
    (Fedora)
  • How to properly install Radeon drivers?
    ... I downloaded FireGL drivers from ati.com, and followed README, which says ... *** Trying to install a precompiled kernel module. ... Tailored kernel module for fglrx not present in your system. ...
    (alt.os.linux.suse)
  • [PATCH 1/3] Audit: break up execve argument lists into multiple records
    ... The limit is currently around 7.5k of arguments as userspace ... memory leak on a malloc failure code path. ... making it harder on the kernel to have the memory it needs. ... int audit_n_rules; ...
    (Linux-Kernel)