• E
    snapshot: fix memory leak on error · 14135609
    Eric Blake 提交于
    Leak introduced in commit 0436d328.  If we allocate an actions array,
    but fail early enough to never consume it with the qemu monitor
    transaction call, we leaked memory.
    
    But our semantics of making the transaction command free the caller's
    memory is awkward; avoiding the memory leak requires making every
    intermediate function in the call chain check for error.  It is much
    easier to fix things so that the function that allocates also frees,
    while the call chain leaves the caller's data intact.  To do that,
    I had to hack our JSON data structure to make it easy to protect a
    portion of an arbitrary JSON tree from being freed.
    
    * src/util/json.h (virJSONType): Name the enum.
    (_virJSONValue): New field.
    * src/util/json.c (virJSONValueFree): Use it to protect a portion
    of an array.
    * src/qemu/qemu_monitor_json.c (qemuMonitorJSONTransaction): Avoid
    freeing caller's data.
    * src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive):
    Free actions array on failure.
    14135609
qemu_driver.c 406.6 KB