#50983 Issue 49437 - Fix memory leak with indirect COS
Closed 3 years ago by spichugi. Opened 4 years ago by mreynolds.
mreynolds/389-ds-base issue49437  into  master

@@ -2372,6 +2372,9 @@ 

                                              *out_attr = tmp_vals;

                                              tmp_vals = NULL;

                                          }

+                                     } else if (out_attr == NULL && tmp_vals) {

+                                         slapi_valueset_free(tmp_vals);

+                                         tmp_vals = NULL;

                                      }

                                  }

  

@@ -1777,7 +1777,7 @@ 

      struct ldbminfo *li = NULL;

      bdb_config *oconf = NULL;

      bdb_config *conf = NULL;

-     dblayer_private *priv;

+     dblayer_private *priv = NULL;

      char *subname = NULL;

      int envflags = 0;

      int dbflags = 0;

file modified
+21 -18
@@ -2004,6 +2004,24 @@ 

      return 0;

  }

  

+ /*

+     vattr_delete_attrvals

+     ---------------------

+     deletes a value list

+ */

+ void

+ vattr_delete_attrvals(objAttrValue **attrval)

+ {

+     objAttrValue *val = *attrval;

+ 

+     while (val) {

+         objAttrValue *next = val->pNext;

+         slapi_value_free(&val->val);

+         slapi_ch_free((void **)&val);

+         val = next;

+     }

+ }

+ 

  void

  vattr_map_entry_free(vattr_map_entry *vae)

  {
@@ -2016,6 +2034,9 @@ 

          }

          list_entry = next_entry;

      }

+     if (vae->objectclasses) {

+         vattr_delete_attrvals(&(vae->objectclasses));

+     }

      slapi_ch_free_string(&(vae->type_name));

      slapi_ch_free((void **)&vae);

  }
@@ -2103,24 +2124,6 @@ 

  }

  

  /*

-     vattr_delete_attrvals

-     ---------------------

-     deletes a value list

- */

- void

- vattr_delete_attrvals(objAttrValue **attrval)

- {

-     objAttrValue *val = *attrval;

- 

-     while (val) {

-         objAttrValue *next = val->pNext;

-         slapi_value_free(&val->val);

-         slapi_ch_free((void **)&val);

-         val = next;

-     }

- }

- 

- /*

      vattr_add_attrval

      -----------------

      adds a value to an attribute value list

Bug Description:

There are two leaks when dealing with indirect COS. The first leak is caused by the COS cache entry's objectclass list not being freed when the entry is removed from the hash table.

The other leak is caused when we follow an indirect pointer COS and do not free a tmp value set that goes unused.

Fix description:

Free the COS entry objectclass list when removing an entry from the hash table. When querying a COS attribute and the returned attribute (out_attr) is NULL, then free the unused tmp_val ValueSet as it's not consumed by anything.

Fixes: https://pagure.io/389-ds-base/issue/49437

Minor nitpick, { } around the vattr_delete_attrvals here.

Besides that I don't see anything wrong with this :) ack

the patch looks good to me as weel. ack

rebased onto 1c06f8c

4 years ago

Pull-Request has been merged by mreynolds

4 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This pull request has been cloned to Github as issue and is available here:
- https://github.com/389ds/389-ds-base/issues/4036

If you want to continue to work on the PR, please navigate to the github issue,
download the patch from the attachments and file a new pull request.

Thank you for understanding. We apologize for all inconvenience.

Pull-Request has been closed by spichugi

3 years ago