BufBuilder copy, assignment memory double-frees memory

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Minor - P4
    • 1.7.1
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      This code issue is minor because it is not currently triggered by existing code.

      StringBuilder uses a BufBuilder (bson/util/builder.h) to manually manage a char buffer. The default copy constructor and operator= will shallow copy the data pointer, which will ultimately lead to freeing the memory multiple times. You can produce the issue with:
      {
      StringBuffer a;

      { StringBuffer b=a; }

      // b d'tor frees b.data, which == a.data

      { StringBuffer c(a); }

      // c d'tor frees a.data again

      } // a d'tor frees a.data again

            Assignee:
            Alberto Lerner (Inactive)
            Reporter:
            Matt Taylor
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: