const struct target_desc *
file_read_description_xml (const char *filename)
{
- struct target_desc *tdesc;
- char *tdesc_str;
- struct cleanup *back_to;
-
- tdesc_str = xml_fetch_content_from_file (filename, NULL);
+ gdb::unique_xmalloc_ptr<char> tdesc_str
+ = xml_fetch_content_from_file (filename, NULL);
if (tdesc_str == NULL)
{
warning (_("Could not open \"%s\""), filename);
return NULL;
}
- back_to = make_cleanup (xfree, tdesc_str);
-
- tdesc = tdesc_parse_xml (tdesc_str, xml_fetch_content_from_file,
- (void *) ldirname (filename).c_str ());
- do_cleanups (back_to);
-
- return tdesc;
+ return tdesc_parse_xml (tdesc_str.get (), xml_fetch_content_from_file,
+ (void *) ldirname (filename).c_str ());
}
/* Read a string representation of available features from the target,
is "target.xml". Other calls may be performed for the DTD or
for <xi:include>. */
-static char *
+static gdb::unique_xmalloc_ptr<char>
fetch_available_features_from_target (const char *name, void *baton_)
{
struct target_ops *ops = (struct target_ops *) baton_;
const struct target_desc *
target_read_description_xml (struct target_ops *ops)
{
- struct target_desc *tdesc;
- char *tdesc_str;
- struct cleanup *back_to;
-
- tdesc_str = fetch_available_features_from_target ("target.xml", ops);
+ gdb::unique_xmalloc_ptr<char> tdesc_str
+ = fetch_available_features_from_target ("target.xml", ops);
if (tdesc_str == NULL)
return NULL;
- back_to = make_cleanup (xfree, tdesc_str);
- tdesc = tdesc_parse_xml (tdesc_str,
- fetch_available_features_from_target,
- ops);
- do_cleanups (back_to);
-
- return tdesc;
+ return tdesc_parse_xml (tdesc_str.get (),
+ fetch_available_features_from_target,
+ ops);
}
/* Fetches an XML target description using OPS, processing
struct target_desc *tdesc;
gdb::unique_xmalloc_ptr<char>
- tdesc_str (fetch_available_features_from_target ("target.xml", ops));
+ tdesc_str = fetch_available_features_from_target ("target.xml", ops);
if (tdesc_str == NULL)
return {};