]> Savannah Git Hosting - gnulib.git/commitdiff
csharpcomp: Fix memory management bug (regression yesterday).
authorBruno Haible <bruno@clisp.org>
Wed, 9 Oct 2024 01:05:33 +0000 (03:05 +0200)
committerBruno Haible <bruno@clisp.org>
Wed, 9 Oct 2024 01:05:33 +0000 (03:05 +0200)
* lib/csharpcomp.c (compile_csharp_using_sscli): Allocate the source
options with malloc() always, not sometimes with malloca() and sometimes
with malloc().

ChangeLog
lib/csharpcomp.c

index 27e1dca18cac7ec169018b16f7cb467093185c9a..1ddf1e11b6651c5a114760d247bd9036c6ccf88b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-10-08  Bruno Haible  <bruno@clisp.org>
+
+       csharpcomp: Fix memory management bug (regression yesterday).
+       * lib/csharpcomp.c (compile_csharp_using_sscli): Allocate the source
+       options with malloc() always, not sometimes with malloca() and sometimes
+       with malloc().
+
 2024-10-07  Bruno Haible  <bruno@clisp.org>
 
        csharpcomp: Improve Cygwin support.
index a0139c5b851ce2d0265fefc725e79299b22ec041..71e96333555af467ef8132a5a54bc9d4667d8534 100644 (file)
@@ -324,7 +324,7 @@ compile_csharp_using_sscli (const char * const *sources,
          we need to use cygpath_w.  */
       malloced =
         (char **)
-        xmalloca ((1 + libdirs_count + sources_count) * sizeof (char *));
+        xmalloca ((1 + libdirs_count + sources_count * 2) * sizeof (char *));
       mallocedp = malloced;
 
       argc =
@@ -377,10 +377,10 @@ compile_csharp_using_sscli (const char * const *sources,
                          10) == 0)
             {
               char *option =
-                (char *) xmalloca (10 + strlen (source_file_converted) + 1);
-
+                (char *) xmalloc (10 + strlen (source_file_converted) + 1);
               memcpy (option, "-resource:", 10);
               strcpy (option + 10, source_file_converted);
+              *mallocedp++ = option;
               *argp++ = option;
             }
           else
@@ -404,9 +404,6 @@ compile_csharp_using_sscli (const char * const *sources,
 
       for (i = 2; i < 3 + libdirs_count + libraries_count; i++)
         freea ((char *) argv[i]);
-      for (i = 0; i < sources_count; i++)
-        if (argv[argc - sources_count + i] != sources[i])
-          freea ((char *) argv[argc - sources_count + i]);
       while (mallocedp > malloced)
         free (*--mallocedp);
       freea (argv);