473,729 Members | 2,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

memory leak (definition?)

Does the following constitute a memory leak?

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

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

Dec 27 '05 #1
7 1698
On 27 Dec 2005 12:27:09 -0800, "bill" <bi**********@g mail.com> wrote
in comp.lang.c:
Does the following constitute a memory leak?

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

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
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? 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're asking in the wrong place. "execv" is not a standard C
function, it is a system-specific extension. So that function, and
"kernel modules", are off-topic here.

You need to ask in a platform-specific group. Since you posted via
Google, your headers do not provide useful information. Perhaps you
want news:comp.unix. programmer or something in the
news:comp.os.li nux.development .* family.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.l earn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Dec 27 '05 #2
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_NUMB ER);
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.progr ammer,
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.
Dec 28 '05 #3
Flash Gordon <sp**@flash-gordon.me.uk> wrote:
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.


Depends on which 3rd party wrote the kernel module, really.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Dec 28 '05 #4
>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_NUMB ER);
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
Dec 28 '05 #5

Gordon Burditt wrote:
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.


That is, unfortunately, what I thought would be the case. Thanks
for the response.

Dec 28 '05 #6
Christopher Benson-Manica wrote:
Flash Gordon <sp**@flash-gordon.me.uk> wrote:
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.


Depends on which 3rd party wrote the kernel module, really.


Also, it depends highly on the quality of the documentation
provided with the module. The correct solution in this particular
situation is to stop using their software, but that's out
of my hands. Since my code is doing exactly 2 things:
calling their function to allocate a data structure and then calling
their code to free it, and their documentation claims that these
2 functions work together, it is in fact highly unlikely that the
problem is in my code. My understanding of their software
is sufficient to recognize that it is crap and that proper use
constitutes placing it in the garbage can.

My original question, which I can phrase more succinctly thanks
to Gordon Burditt's response, is whether the exec family of functions
will
play nicely with kernel memory. That question was posted here
only as an ancillary to what I thought was an interesting toy
question regarding the definition of a memory leak which I
thought might be interesting to some of the people
reading comp.lang.c. If you feel that it is entirely off topic
than the correct response is to either make no response
or respond outside of the group. The C language is and
has always been closely tied to the Unix heritage, and IMO
questions regarding the behavior of low-level functions
such as the exec family are in fact relevant to the language and
to this newsgroup. I recognize that many people have tried
to divorce this group from anything beyond the language
proper, and that is in fact why I don't bother reading the group
very often anymore.

Dec 28 '05 #7
bill wrote:
Christopher Benson-Manica wrote:
Flash Gordon <sp**@flash-gordon.me.uk> wrote:
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. Depends on which 3rd party wrote the kernel module, really.


Also, it depends highly on the quality of the documentation
provided with the module.


My comment was based on you saying, "Rather than trying to figure out
the proper usage of their library." From the perspective of someone not
knowing you it makes it look likely that you are not using the library
correctly.
The correct solution in this particular
situation is to stop using their software, but that's out
of my hands. Since my code is doing exactly 2 things:
calling their function to allocate a data structure and then calling
their code to free it, and their documentation claims that these
2 functions work together, it is in fact highly unlikely that the
problem is in my code. My understanding of their software
is sufficient to recognize that it is crap and that proper use
constitutes placing it in the garbage can.
Quite possibly, but the information you provided originally was that you
didn't understand their software, but thought it was buggy.

<snip>
or respond outside of the group. The C language is and
has always been closely tied to the Unix heritage, and IMO
questions regarding the behavior of low-level functions
such as the exec family are in fact relevant to the language and
to this newsgroup.
What you think is not the majority opinion around here.
I recognize that many people have tried
to divorce this group from anything beyond the language
proper, and that is in fact why I don't bother reading the group
very often anymore.


Since you know the general opinion is that things like the exec family
of functions are off topic I'm sure you are also aware of groups such as
comp.unix.progr ammer and that such questions are more likely to be
on-topic there, so why not ask in a group where your question is topical
instead of when where you already *know* it will be considered off topic?
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Dec 28 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2431
by: mensanator | last post by:
Since the following discussion took place (unresolved), <http://groups.google.com/group/comp.lang.python/browse_frm/thread/c3bd08ef3e4c478a/2b54deb522c9b9d9?lnk=st&q=divm()+memory+leak+group:comp.lang.python+author:mensanator&rnum=1&hl=en#2b54deb522c9b9d9> I've kept it in the back of my mind as I've been learning to use the base gmp library in c. Now I believe I know what the problem is. First, divm() is not a gmp function. It is a...
8
3412
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? In nut shell, what is/are the realtion/s between the Memory Leak and Memory Corruption. Juts Theoritical Assumtion below:
8
8549
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of each object within my JS app to help locate my problem? Thanks
3
5324
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". Anybody know anything about this? Does *Javascript* leak memeory, or does the *browser* leak memory?
18
9072
by: happyvalley | last post by:
Hi, basically, the test function get a char pointer, and assigned a string to it. then the string is passed back by the call-by-reference mechanism. in test(), I reallocate some memory for the pointer, the size is not fixed. I remember, all new statement should be followed by a delete statement, is there some memory leak here?
7
1246
by: Ge Chunyuan | last post by:
Eg. we have the class hiaerarchy Point inherit Point3D class Point { public: Point(int a=0,char* b=0):x(a),y(b){} private: int x; char* y; };
27
2954
by: George2 | last post by:
Hello everyone, Should I delete memory pointed by pointer a if there is bad_alloc when allocating memory in memory pointed by pointer b? I am not sure whether there will be memory leak if I do not delete a. try { a = new int ;
3
3234
by: not_a_commie | last post by:
The CLR won't garbage collect until it needs to. You should see the memory usage climb for some time before stabilizing. Can you change your declaration to use the 'out' keyword rather than a 'ref' keyword?
16
5096
by: graham.keellings | last post by:
hi, I'm looking for an open source memory pool. It's for use on an embedded system, if that makes any difference. Something with garbage collection/defragmentation would be nice. It should have the ability to allocate different size chunks of memory not just a single size. It should error check for double free, etc. And it should be usable by a mixture of C and C++ subsystems. If I get that, I'm happy. Thank you very much.
0
8917
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.