From fe3fa0e1be7d11d77c33104b585fa8cb99e4320f Mon Sep 17 00:00:00 2001 From: Marco van Wieringen Date: Sun, 11 Oct 2009 20:21:36 +0200 Subject: [PATCH] Small update to cache the current attrspace we are saving and make a private copy of that string representation. --- bacula/src/filed/xattr.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/bacula/src/filed/xattr.c b/bacula/src/filed/xattr.c index 1d54625ac0..0353053b1b 100644 --- a/bacula/src/filed/xattr.c +++ b/bacula/src/filed/xattr.c @@ -648,7 +648,7 @@ static bxattr_exit_code bsd_build_xattr_streams(JCR *jcr, FF_PKT *ff_pkt) uint32_t expected_serialize_len = 0; unsigned int namespace_index; int attrnamespace; - char *current_attrnamespace, current_attrname[BUFSIZ], current_attrtuple[BUFSIZ]; + char *current_attrnamespace = NULL, current_attrname[BUFSIZ], current_attrtuple[BUFSIZ]; xattr_t *current_xattr; alist *xattr_value_list = NULL; bxattr_exit_code retval = bxattr_exit_error; @@ -662,6 +662,19 @@ static bxattr_exit_code bsd_build_xattr_streams(JCR *jcr, FF_PKT *ff_pkt) for (namespace_index = 0; namespace_index < sizeof(os_default_xattr_namespaces) / sizeof(int); namespace_index++) { attrnamespace = os_default_xattr_namespaces[namespace_index]; + /* + * Convert the numeric attrnamespace into a string representation and make a private copy of that string. + */ + if (extattr_namespace_to_string(attrnamespace, ¤t_attrnamespace) != 0) { + Mmsg2(jcr->errmsg, _("Failed to convert %d into namespace on file \"%s\"\n"), + attrnamespace, jcr->last_fname); + Dmsg2(100, "Failed to convert %d into namespace on file \"%s\"\n", + attrnamespace, jcr->last_fname); + goto bail_out; + } + + current_attrnamespace = bstrdup(current_attrnamespace); + /* * First get the length of the available list with extended attributes. */ @@ -725,17 +738,6 @@ static bxattr_exit_code bsd_build_xattr_streams(JCR *jcr, FF_PKT *ff_pkt) * First make a xattr tuple of the current namespace and the name of the xattr. * e.g. something like user. or system. */ - if (extattr_namespace_to_string(attrnamespace, ¤t_attrnamespace) != 0) { - Mmsg2(jcr->errmsg, _("Failed to convert %d into namespace on file \"%s\"\n"), - attrnamespace, jcr->last_fname); - Dmsg2(100, "Failed to convert %d into namespace on file \"%s\"\n", - attrnamespace, jcr->last_fname); - goto bail_out; - } - - /* - * Create a tupple of the current attrnamespace and attrname. - */ bsnprintf(current_attrtuple, sizeof(current_attrtuple), "%s.%s", current_attrnamespace, current_attrname); /* @@ -853,6 +855,8 @@ static bxattr_exit_code bsd_build_xattr_streams(JCR *jcr, FF_PKT *ff_pkt) xattr_value_list->append(current_xattr); xattr_count++; + + free(current_attrnamespace); } /* @@ -892,6 +896,9 @@ static bxattr_exit_code bsd_build_xattr_streams(JCR *jcr, FF_PKT *ff_pkt) } bail_out: + if (current_attrnamespace) { + free(current_attrnamespace); + } if (xattr_list) { free(xattr_list); } -- 2.39.5