Description: Fix concurrent reading of extended attributes (xattrs)
Author: Hannes von Haugwitz <hannes@vonhaugwitz.com>
Origin: 732e7e2e7dc91bb614c508518c0abc6cab85565c
Date: Mon May 16 13:30:00 2024 +0200
Forwarded: not-needed
--- a/src/do_md.c
+++ b/src/do_md.c
@@ -478,14 +478,13 @@ static void xattr_add(xattrs_type *xattr
 void xattrs2line(db_line *line) {
     /* get all generic user xattrs. */
     xattrs_type *xattrs = NULL;
-    static ssize_t xsz = 1024;
-    static char *xatrs = NULL;
     ssize_t xret = -1;
 
     if (!(ATTR(attr_xattrs)&line->attr))
         return;
 
-    if (!xatrs) xatrs = checked_malloc(xsz);
+    ssize_t xsz = 1024;
+    char *xatrs = xatrs = checked_malloc(xsz);
 
     while (((xret = llistxattr(line->fullpath, xatrs, xsz)) == -1) && (errno == ERANGE)) {
         xsz <<= 1;
@@ -498,10 +497,8 @@ void xattrs2line(db_line *line) {
         log_msg(LOG_LEVEL_WARNING, "listxattrs failed for %s:%s", line->fullpath, strerror(errno));
     } else if (xret) {
         const char *attr = xatrs;
-        static ssize_t asz = 1024;
-        static char *val = NULL;
-
-        if (!val) val = checked_malloc(asz);
+        ssize_t asz = 1024;
+        char *val = checked_malloc(asz);
 
         xattrs = xattr_new();
 
@@ -529,7 +526,9 @@ next_attr:
             attr += len + 1;
             xret -= len + 1;
         }
+        free(val);
     }
+    free(xatrs);
 
     line->xattrs = xattrs;
 }
