[Lldb-commits] [PATCH] D116707: [lldb] fix memory leak in "GetGDBServerRegisterInfoXMLAndProcess"

Pavel Labath via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Jan 6 05:21:06 PST 2022


labath added a comment.

In D116707#3223998 <https://reviews.llvm.org/D116707#3223998>, @JDevlieghere wrote:

> We shouldn't have to manage memory at this granularity. Why isn't `xmlFreeDoc` cleaning this up?

Because xmlGetProp <http://www.xmlsoft.org/html/libxml-tree.html#xmlGetProp> returns a value that's independent of the containing document.

That said, I agree this is a pretty bad encapsulation breakage (and will not compile in !LLDB_ENABLE_LIBXML builds).

One way to fix this (if we wanted to be fancy) is to have this function return a `std::unique_ptr<char>` with a custom deleter (xmlFree), but given that this is hardly performance sensitive code, I would just copy the attribute value into a std::string inside `GetAttributeValue`, and then have it return *that* (after freeing the original string).

In either case, this function only has a handful of callers, so it should be pretty easy to update it to use a saner API.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116707/new/

https://reviews.llvm.org/D116707



More information about the lldb-commits mailing list