diff -u a/src/libpst.c b/src/libpst.c
--- a/src/libpst.c	2020-06-16 20:00:35.000000000 -0400
+++ b/src/libpst.c	2021-03-18 10:51:45.000000000 -0400
@@ -4459,20 +4463,21 @@
 
 /** Convert str to rfc2231 encoding of str
  *
- *  @param str   pointer to the mapi string of interest
+ *  @param str   pointer to the string of interest
+ *  @return pointer to converted string - caller must free
  */
-void pst_rfc2231(pst_string *str) {
+char * pst_rfc2231(char *str) {
     int needs = 0;
-    const int8_t *x = (int8_t *)str->str;
+    const int8_t *x = (int8_t *)str;
     while (*x) {
         if (*x <= 32) needs++;
         x++;
     }
-    int n = strlen(str->str) + 2*needs + 15;
+    int n = strlen(str) + 2*needs + 15;
     char *buffer = pst_malloc(n);
     strcpy(buffer, "utf-8''");
-    x = (int8_t *)str->str;
-    const uint8_t *y = (uint8_t *)str->str;
+    x = (int8_t *)str;
+    const uint8_t *y = (uint8_t *)str;
     uint8_t *z = (uint8_t *)buffer;
     z += strlen(buffer);    // skip the utf8 prefix
     while (*y) {
@@ -4488,8 +4493,7 @@
         y++;
     }
     *z = '\0';
-    free(str->str);
-    str->str = buffer;
+    return buffer;
 }
 
 
diff -u a/src/libpst.h b/src/libpst.h
--- a/src/libpst.h	2020-06-16 20:00:35.000000000 -0400
+++ b/src/libpst.h	2021-03-18 10:51:52.000000000 -0400
@@ -1118,7 +1125,7 @@
 /** Convert str to rfc2231 encoding of str
  *  @param str   pointer to the mapi string of interest
  */
-void            pst_rfc2231(pst_string *str);
+char *          pst_rfc2231(char *str);
 
 
 /** Convert str to rfc2047 encoding of str, possibly enclosed in quotes if it contains spaces
diff -u a/src/readpst.c b/src/readpst.c
--- a/src/readpst.c	2020-06-16 20:00:35.000000000 -0400
+++ b/src/readpst.c	2021-03-18 11:07:53.000000000 -0400
@@ -1210,8 +1210,9 @@
         // use the long filename, converted to proper encoding if needed.
         // it is already utf8
         char *escaped = quote_string(attach->filename2.str);
-        pst_rfc2231(&attach->filename2);
-        fprintf(f_output, "Content-Disposition: attachment; \n        filename*=%s;\n", attach->filename2.str);
+        char *rfc2231 = pst_rfc2231(attach->filename2.str);
+        fprintf(f_output, "Content-Disposition: attachment; \n        filename*=%s;\n", rfc2231);
+        free(rfc2231);
         // Also include the (escaped) utf8 filename in the 'filename' header directly - this is not strictly valid
         // (since this header should be ASCII) but is almost always handled correctly (and in fact this is the only
         // way to get MS Outlook to correctly read a UTF8 filename, AFAICT, which is why we're doing it).
