Blame SOURCES/fix-memory-leak-in-vasnprintf.patch

2b4d5b
diff -ru libunistring-0.9.10/lib/vasnprintf.c libunistring-0.9.10.new/lib/vasnprintf.c
2b4d5b
--- libunistring-0.9.10/lib/vasnprintf.c	2018-05-25 18:02:16.000000000 +0200
2b4d5b
+++ libunistring-0.9.10.new/lib/vasnprintf.c	2021-06-14 17:06:43.084948649 +0200
2b4d5b
@@ -1864,7 +1864,7 @@
2b4d5b
 
2b4d5b
     /* Ensures that allocated >= needed.  Aborts through a jump to
2b4d5b
        out_of_memory if needed is SIZE_MAX or otherwise too big.  */
2b4d5b
-#define ENSURE_ALLOCATION(needed) \
2b4d5b
+#define ENSURE_ALLOCATION_ELSE(needed, oom_statement) \
2b4d5b
     if ((needed) > allocated)                                                \
2b4d5b
       {                                                                      \
2b4d5b
         size_t memory_size;                                                  \
2b4d5b
@@ -1875,17 +1875,19 @@
2b4d5b
           allocated = (needed);                                              \
2b4d5b
         memory_size = xtimes (allocated, sizeof (DCHAR_T));                  \
2b4d5b
         if (size_overflow_p (memory_size))                                   \
2b4d5b
-          goto out_of_memory;                                                \
2b4d5b
+          oom_statement                                                      \
2b4d5b
         if (result == resultbuf || result == NULL)                           \
2b4d5b
           memory = (DCHAR_T *) malloc (memory_size);                         \
2b4d5b
         else                                                                 \
2b4d5b
           memory = (DCHAR_T *) realloc (result, memory_size);                \
2b4d5b
         if (memory == NULL)                                                  \
2b4d5b
-          goto out_of_memory;                                                \
2b4d5b
+          oom_statement                                                      \
2b4d5b
         if (result == resultbuf && length > 0)                               \
2b4d5b
           DCHAR_CPY (memory, result, length);                                \
2b4d5b
         result = memory;                                                     \
2b4d5b
       }
2b4d5b
+#define ENSURE_ALLOCATION(needed) \
2b4d5b
+  ENSURE_ALLOCATION_ELSE((needed), goto out_of_memory; )
2b4d5b
 
2b4d5b
     for (cp = format, i = 0, dp = &d.dir[0]; ; cp = dp->dir_end, i++, dp++)
2b4d5b
       {
2b4d5b
@@ -2137,7 +2139,8 @@
2b4d5b
                           }
2b4d5b
                         if (converted != result + length)
2b4d5b
                           {
2b4d5b
-                            ENSURE_ALLOCATION (xsum (length, converted_len));
2b4d5b
+                            ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
2b4d5b
+                                                    { free (converted); goto out_of_memory; });
2b4d5b
                             DCHAR_CPY (result + length, converted, converted_len);
2b4d5b
                             free (converted);
2b4d5b
                           }
2b4d5b
@@ -2263,7 +2266,8 @@
2b4d5b
                           }
2b4d5b
                         if (converted != result + length)
2b4d5b
                           {
2b4d5b
-                            ENSURE_ALLOCATION (xsum (length, converted_len));
2b4d5b
+                            ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
2b4d5b
+                                                    { free (converted); goto out_of_memory; });
2b4d5b
                             DCHAR_CPY (result + length, converted, converted_len);
2b4d5b
                             free (converted);
2b4d5b
                           }
2b4d5b
@@ -2389,7 +2393,8 @@
2b4d5b
                           }
2b4d5b
                         if (converted != result + length)
2b4d5b
                           {
2b4d5b
-                            ENSURE_ALLOCATION (xsum (length, converted_len));
2b4d5b
+                            ENSURE_ALLOCATION_ELSE (xsum (length, converted_len),
2b4d5b
+                                                    { free (converted); goto out_of_memory; });
2b4d5b
                             DCHAR_CPY (result + length, converted, converted_len);
2b4d5b
                             free (converted);
2b4d5b
                           }
2b4d5b
@@ -2914,7 +2919,8 @@
2b4d5b
                         }
2b4d5b
                     }
2b4d5b
 #  else
2b4d5b
-                  ENSURE_ALLOCATION (xsum (length, tmpdst_len));
2b4d5b
+                  ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
2b4d5b
+                                          { free (tmpdst); goto out_of_memory; });
2b4d5b
                   DCHAR_CPY (result + length, tmpdst, tmpdst_len);
2b4d5b
                   free (tmpdst);
2b4d5b
                   length += tmpdst_len;
2b4d5b
@@ -5368,7 +5374,8 @@
2b4d5b
                             errno = saved_errno;
2b4d5b
                             return NULL;
2b4d5b
                           }
2b4d5b
-                        ENSURE_ALLOCATION (xsum (length, tmpdst_len));
2b4d5b
+                        ENSURE_ALLOCATION_ELSE (xsum (length, tmpdst_len),
2b4d5b
+                                                { free (tmpdst); goto out_of_memory; });
2b4d5b
                         DCHAR_CPY (result + length, tmpdst, tmpdst_len);
2b4d5b
                         free (tmpdst);
2b4d5b
                         count = tmpdst_len;
2b4d5b
libunistring-0.9.10.new/lib のみに存在: vasnprintf.c.orig