• L
    util: standardize return from functions calling virNetlinkCommand · 0208face
    Laine Stump 提交于
    There are several functions that call virNetlinkCommand, and they all
    follow a common pattern, with three exit labels: err_exit (or
    cleanup), malformed_resp, and buffer_too_small. All three of these
    labels do their own cleanup and have their own return. However, the
    malformed_resp label usually frees the same items as the
    cleanup/err_exit label, and the buffer_too_small label just doesn't
    free recvbuf (because it's known to always be NULL at the time we goto
    buffer_too_small.
    
    In order to simplify and standardize the code, I've made the following
    changes to all of these functions:
    
    1) err_exit is replaced with the more libvirt-ish "cleanup", which
       makes sense because in all cases this code is also executed in the
       case of success, so labelling it err_exit may be confusing.
    
    2) rc is initialized to -1, and set to 0 just before the cleanup
       label. Any code that currently sets rc = -1 is made to instead goto
       cleanup.
    
    3) malformed_resp and buffer_too_small just log their error and goto
       cleanup. This gives us a single return path, and a single place to
       free up resources.
    
    4) In one instance, rather then logging an error immediately, a char*
       msg was pointed to an error string, then goto cleanup (and cleanup
       would log an error if msg != NULL). It takes no more lines of code
       to just log the message as we encounter it.
    
    This patch should have 0 functional effects.
    0208face
virnetdevmacvlan.c 33.7 KB