home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16678 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  1.8 KB

  1. From: kevinc@hpcc01.corp.hp.com (Kevin Collins)
  2. Date: Fri, 20 Nov 1992 16:20:13 GMT
  3. Subject: SC List Memory Leak?
  4. Message-ID: <1000011@hpcc01.corp.hp.com>
  5. Organization: the HP Corporate notes server
  6. Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!hpscit.sc.hp.com!scd.hp.com!hpscdm!hplextra!hpcc05!hpcc01!kevinc
  7. Newsgroups: comp.lang.c++
  8. Lines: 56
  9.  
  10.  
  11. I've been using an internal tool to detect memory leaks in some linked
  12. lists we use.  I've been unable to get the SC List class to pass cleanly
  13. and want to know where I am going wrong. 
  14.  
  15. I've got a simple program which reads /etc/passwd, sticks Password objects
  16. onto a PasswordList class (with the put function), derived from SC List, 
  17. then deletes them and the List itself.  The two versions of the commands 
  18. used to delete the objects on the List are :
  19.  
  20.     // method 1
  21.  
  22.     Password* P;
  23.  
  24.     if (length () > 0) {
  25.  
  26.         while ((*this).unput (P) != 0)
  27.             delete P;
  28.      }
  29.  
  30.     // method 2
  31.  
  32.     Password* PP;
  33.  
  34.     while ((void*)(*this)) {
  35.         (*this).unput (PP);
  36.             delete PP;
  37.     }
  38.  
  39.     cout << "length = " << length () << endl;
  40.  
  41. Both of these result in output like :
  42.  
  43. only in dump 2: 1012 bytes, trace = malloc+0x0000004f
  44.         mbschr+0x000000db
  45.         __d_syserror+0x807a2207
  46.         Pool::grow(void)+0x00000013
  47.         D$4+0x0000002f
  48.         D$6+0x00000027
  49.         D$17+0x00000023
  50.         fill__12PasswordListFv+0x0000027f
  51.         main+0x00000097
  52.  
  53. This basically shows the stack of calls that lead to the memory which 
  54. was not de-allocated.  'fill__12PasswordListFv' is the 'fill" method of 
  55. my PasswordList class.  The call of "Pool::grow(void) is apparently 
  56. something called by the List code which eventually calls malloc.
  57.  
  58. Are my methods of clearing the List insufficient?  Is there something
  59. else wrong?  
  60.  
  61. Please email any responses.
  62.  
  63. Thanks,
  64.  
  65. Kevin
  66.