You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Free the non-blocking error array before a raise - #613
nogvl_cleanup raises the first SQL Server error with rb_exc_raise. A raise from C is a longjmp: it leaves the function at once. Thus the free(userdata->nonblocking_errors) call after the loop does not run.
nogvl_setup allocates this array with malloc for ERRORS_STACK_INIT_SIZE errors. The array is 4,136 bytes on 64-bit Linux. Each query that fails leaks one array, because the next nogvl_setup call replaces the pointer.
Fix
Copy the collected errors into a buffer that Ruby manages (RB_ALLOCV_N).
Free the malloc array and reset its fields.
Process the copy as before: call the message handler for info messages, then raise the first error.
RB_ALLOCV_N registers the copy with the GC. If the message handler or the raise leaves the function before RB_ALLOCV_END, the GC frees the copy. The order of the messages does not change. The raised exception does not change.
Measurements
The tool is ruby_memcheck 3.0.1. It runs Ruby under Valgrind and removes the false positives that Ruby causes. A "definitely lost" block is a block with no pointer to it at exit.
Problem
nogvl_cleanupraises the first SQL Server error withrb_exc_raise. A raise from C is alongjmp: it leaves the function at once. Thus thefree(userdata->nonblocking_errors)call after the loop does not run.nogvl_setupallocates this array withmallocforERRORS_STACK_INIT_SIZEerrors. The array is 4,136 bytes on 64-bit Linux. Each query that fails leaks one array, because the nextnogvl_setupcall replaces the pointer.Fix
RB_ALLOCV_N).mallocarray and reset its fields.RB_ALLOCV_Nregisters the copy with the GC. If the message handler or the raise leaves the function beforeRB_ALLOCV_END, the GC frees the copy. The order of the messages does not change. The raised exception does not change.Measurements
The tool is ruby_memcheck 3.0.1. It runs Ruby under Valgrind and removes the false positives that Ruby causes. A "definitely lost" block is a block with no pointer to it at exit.
master