PC-lint/FlexeLint Output | Reference Manual Explanation | Home Page

            bug1540.cpp

1     class A
2         {
3         int *p;
4       public:
5         A( int n = 1 )
6             {
7             p = new int[n];
8             }
9         ~A() { }
10        };
11
12    void f( int n, int m )
13        {
14        A a(100000);
15        if( n ) for( int i = 0; i < m; i++ ) f(n-1,2*m);
16        }
17
18    int main() { f( 6, 1 ); return 0; }

Running this program under one compiler caused a crash. Under another compiler it seems to run for an excessively long time. Can you spot the problem? (hint: it has to do with memory)


bug1540.cpp lint Output

--- Module:   bug1540.cpp
            _
        p = new int[n];
bug1540.cpp  7  Info 1732: new in constructor for class 'A' which has no
    assignment operator
bug1540.cpp  7  Info 1733: new in constructor for class 'A' which has no copy
    constructor
bug1540.cpp  7  Info 737: Loss of sign in promotion from int to unsigned int
           _
    ~A() { }
bug1540.cpp  9  Warning 1540: Pointer member 'A::p' (line 3) neither freed nor
    zero'ed by destructor

Reference Manual Explanation

 
1540  pointer member 'Symbol' (Location) neither freed nor zero'ed
      by destructor  -- The indicated member is a non-static pointer
      member of a class that was apparently not freed by the class'
      destructor.  Was this an oversight?  By freeing, we mean either
      a call to the free() function or use of the delete operator. If
      the pointer is only intended to point to static information during
      its lifetime then, of course, it never should be freed.  In that
      case you should signal closure by assigning it the NULL pointer (0).

If you have comments or questions about this bug, please post them to our   Discussion Forum

Previous Bug - Bug #1738 - February 2003

PC-lint/FlexeLint - Product Overview

Home | Contact | Order

PC-lint and FlexeLint are trademarks of Gimpel Software
Copyright 2003, Gimpel Software