• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Facing an issue with leaks utility in mac in usage with the xcode project
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Facing an issue with leaks utility in mac in usage with the xcode project


  • Subject: Re: Facing an issue with leaks utility in mac in usage with the xcode project
  • From: mac adobe <email@hidden>
  • Date: Thu, 30 Apr 2009 22:07:03 +0530

hi
 
the first statement
 
char *c =(char *) malloc(5000*sizeof(char)); allocates 5000 bytes of memory from heap and c pointer points to it

in the next statement the compiler allocates " another " 5000 bytes from heap and now c points to the newly alloted heap memory .

 
the initially alloted heap of 5000 is now "orphaned" and hence a leak as you cannot refer back to that memory . I might have donw some important computations between the two allocations and that has been lost ...
 
This is a leak .
 
 
thanks and regards
manish


Le 30 avr. 09 à 18:17, Luis Vitorio Cargnini a écrit :

Hi all,
Sorry but whiy this:

 char *c =(char *) malloc(5000*sizeof(char));
                                  c=(char *)malloc(5000*sizeof(char));
                                c=NULL;

is a leak ?

for me is only "bad" programming practice, just waste of 5000 bytes (twice), not a leak itself, the program is wasting 5000 bytes, that will be released in two moments one after the application finish, if it works as a daemon ok, your application is gathering 5000 bytes and simple not using it. Also I'm not exactly sure IF the compiler couldn't make this kind of optimization and detect this kind of waste of memory and simply "dump" the machine code, since you are initializing it will allocate the initial memory than put the pointer into the "limbo".
But this is not exactly leak for me as I said is bad programming practice, why do you say this is a leak ?

Le 09-04-30 à 11:29, mac adobe a écrit :

Hi all,

 

I am on lepord 10.5.7 . The following issue was also seen in 10.5.5 .

 

I am facing an issue with leaks utility in mac and would like your comments on the same .

 

I have introduced  leaks explicitly in my xcode test case program through
 
char *p=(char*) malloc(1000*sizeof(char));
p=NULL;

 

As per the man pages of the leaks utility  , it catches all leaked memory – memory that has been allocated but has been lost and cannot be freed . As in the above said case 1000 characters have been allocated and the only pointer to the said 1000 characters has been lost by p=NULL , I expected leaks to tell me this as a leak . However it did not .

 

Do we need to set any variable (environment ) etc to make leaks catch this error ?
I had set the environment variable  by export MallocStackLogging=1 which is used for displaying stack trace AFTER it identifies a leak  .

 

Has anyone else faced similar issues in the past or am I doing it the wrong way . Kindly comment .

 

 

Also I see that

 

1)      Many a times leaks utility gives strange behavior , identifying leaks during a run  and in subsequent runs of the same test program  , not identifying leaks at all .
2)      Identifying leaks only in function calls and not in main program .
3)      Not identifying leaks at all in those cases where an external dll have been used .

 

Let me give you the sample code which I used test using leaks utility on mac .

 

Since it was not giving leaks with 1000 I increased it several times but still no help .

 

#include <iostream>
 
void callme()
{
     char *p=(char *) malloc(1024*1024*sizeof(char));
}
 
int main (int argc, char * const argv[]) {
     int i ;
     std::cin >>i;
     std::cout << "Hello, World!\n";
     callme();
     char *c =(char *) malloc(5000*sizeof(char));
     c=(char *)malloc(5000*sizeof(char));
     c=NULL;
     std::cin >>i;
     return 0;
}

 

 

1)      This code fragment was compiled and then run . and attached to instrument’s leaks utility (during call of first scanf I attached the process with leaks utility) . It is clear that callme() will lead to memory leak . However the leaks utility identified it only once and during reruns of the same test program it failed to identify this as a leak .

 

2)      During cases when leaks utility did identified it as a leak , it failed to identify leaks in main

 

                                char *c =(char *) malloc(5000*sizeof(char));
                                  c=(char *)malloc(5000*sizeof(char));
                                c=NULL;

 

   Note that since c is pointing to memory of  character  5000 and later points to another 5000 different memory , we should get a leak in main also . However leak utility   
   failed to identify this as a leak .

 

        Please note that we did set export MallocStackLogging=1    before running the program in the same terminal window

 

 

 

Has anyone else faced similar issues in the past or am I doing it the wrong way . Kindly comment .

 

 

 

 

Thanks and Regards
Manish
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)

This email sent to email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.

This email sent to email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.

This email sent to email@hidden

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Facing an issue with leaks utility in mac in usage with the xcode project (From: mac adobe <email@hidden>)
 >Re: Facing an issue with leaks utility in mac in usage with the xcode project (From: Luis Vitorio Cargnini <email@hidden>)
 >Re: Facing an issue with leaks utility in mac in usage with the xcode project (From: Jean-Daniel Dupas <email@hidden>)

  • Prev by Date: need way to debug tool called by popen--at startup
  • Next by Date: Re: Facing an issue with leaks utility in mac in usage with the xcode project
  • Previous by thread: Re: Facing an issue with leaks utility in mac in usage with the xcode project
  • Next by thread: Re: Facing an issue with leaks utility in mac in usage with the xcode project
  • Index(es):
    • Date
    • Thread