• Cyrill Gorcunov's avatar
    crtools: Make fdset operations robust against open() errors · 7705df53
    Cyrill Gorcunov authored
    There are two cases for cr_fdset_open
    
     - It might be called with already allocated
       memory so we should reuse it.
    
     - It might be called with NULL pointing out
       that caller expects us to allocate memory.
    
    If an open() error happens somewhere inside cr_fdset_open
    it requires two error paths
    
     - Just close all files opened but don't free memory
       if it was not allocated by us
    
     - Close all files opened *and* free memory allocated
       by us.
    
    In any case we should close all files opened so close_cr_fdset()
    helper is splitted into two parts.
    
    Also the caller should be ready for such semantics as well and
    do not re-assign pointers obtained but simply test for NULL
    on results.
    Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
    Acked-by: 's avatarPavel Emelyanov <xemul@parallels.com>
    7705df53
cr-dump.c 29.2 KB