Which of the following is the better strategy for calling C functions that fill a pre-allocated buffer but might fail?
Option 1. First malloc() a temporary buffer in C, call the desired C function to fill that buffer, and if the C function succeeds then allocate a Scheme string/vector of the same size as the temp buffer and copy the temp buffer into it. If the C function fails, free() the temp buffer and return an error value to Scheme.
Option 2. First allocate a Scheme string/vector of the right size, then call the desired C function to fill it directly. No temporary buffer is used. If the C function fails, free the Scheme object. (Which function in the Gambit FFI does this?)
Does GC present complexities for option 2 (especially when interacting threads and/or signals)?