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

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to