Uploaded image for project: 'Couchbase Server'
  1. Couchbase Server
  2. MB-22217

Use std::string instead of char* in config_strerror()

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Done
    • Minor
    • 5.0.0
    • .master
    • memcached

    Description

      config_strerror() in config_util.cc returns its error string as a C-style string (allocated with malloc via strdup).

      This is undesirable for a number of reasons:

      1. char* is a non-owning type (C-style string), so users must remember to free() it or memory will be leaked (owning types, e.g. std::string are preferred).
      2. To allow us to accurately track memory, we have our own cb_malloc API when we need to use C-style allocation. In this case, using the normal (non-CB) malloc is potentially confusing, as the caller needs to remember to use plain free() and not cb_free() in this case.

      We should therefore change config_strerror() to use C++ string objects instead of C-style allocation:

      • Change the return type of config_strerror to std::string, and update all call-sites.
      • Change the string manipulation from C-style snprintf / strdup to methods on std::string.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            james.harrison James Harrison (Inactive)
            drigby Dave Rigby (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty