[omniORB] Possible memory leakage in string_member

Terry A. Lee terryl@wt.net
Tue, 1 Feb 2000 20:21:54 -0600


While looking at string_member initialization with a static ""
I noticed that if a string_member constructor sets pd_rel to 0
that protects the initialize but then subsequent operations
like assignment, where memory is actually allocated, will result
in leaks. Shouldn't the assignment operations set pd_rel
if they allocate memory? If pd_rel were to remain as 0 this
would leave the duplicated string hanging, the same for the
other assignments, even those that just take ownership so that
they also would be consistant with CORBA spec:

Here is an example operator taken from the current source:

  inline _CORBA_String_member& operator= (const char* s) {
    if (pd_rel && ((char*)_ptr)) {
      delete[] _ptr;
      _ptr = 0;
    }
    if (s) _ptr = _CORBA_String_var::string_dup(s);
    return *this;
  }


Terry Lee
Paradigm Geophysical