On 12/7/17 7:41 AM, Øyvind Hvidsten wrote:

> Bash Version: 4.4
> Patch Level: 12
> Release Status: release
> 
> Description:
>     Somehow the included script causes a memory leak. Memory usage will
> grow huge over a very short timeframe.

Thanks for the report. It's the return in f2 that causes the problem.
This will be fixed in the next devel branch push. If you want to play
around with the fix, I've attached a patch.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/
*** ../bash-20171205/execute_cmd.c      2017-12-08 07:38:28.000000000 -0500
--- execute_cmd.c       2017-12-08 09:54:45.000000000 -0500
***************
*** 750,753 ****
--- 750,755 ----
        ofifo = num_fifos ();
        ofifo_list = copy_fifo_list ((int *)&osize);
+       begin_unwind_frame ("internal_fifos");
+       add_unwind_protect (xfree, ofifo_list);
        saved_fifo = 1;
      }
***************
*** 1078,1081 ****
--- 1080,1084 ----
        close_new_fifos ((char *)ofifo_list, osize);
        free ((void *)ofifo_list);
+       discard_unwind_frame ("internal_fifos");
      }
  #endif
***************
*** 5098,5104 ****
  #endif
  
! #if defined (PROCESS_SUBSTITUTION)  
    ofifo = num_fifos ();
    ofifo_list = copy_fifo_list (&osize);
  #endif
  
--- 5103,5114 ----
  #endif
  
! #if defined (PROCESS_SUBSTITUTION)
!   begin_unwind_frame ("saved_fifos");
!   /* If we return, we longjmp and don't get a chance to restore the old
!      fifo list, so we add an unwind protect to free it */
    ofifo = num_fifos ();
    ofifo_list = copy_fifo_list (&osize);
+   if (ofifo_list)
+     add_unwind_protect (xfree, ofifo_list);
  #endif
  
***************
*** 5179,5183 ****
    if (nfifo > ofifo)
      close_new_fifos (ofifo_list, osize);
!   free (ofifo_list);
  #endif
  
--- 5189,5195 ----
    if (nfifo > ofifo)
      close_new_fifos (ofifo_list, osize);
!   if (ofifo_list)
!     free (ofifo_list);
!   discard_unwind_frame ("saved_fifos");
  #endif
  

Reply via email to