[libvirt] [PATCH 0/4] Make it easier to clean up after using virBuffer

Martin Kletzander mkletzan at redhat.com
Mon Aug 21 07:47:38 UTC 2017

There are many places in the code where virBufferCheckError() is used
and then, right after that, virBufferContentAndReset() is called.  The
former has ATTRIBUTE_RETURN_CHECK, so every occurrence just checks
that.  However, if the return value of the latter is also the return
value of the current function, there is no need to duplicate the work
and act upon the error twice.

This series proposes the idea of virCheckError being used for only
reporting the error [1/4] and shows an example commit on how to clean
up existing functions [2/4] so that it can be posted to our wiki under
https://wiki.libvirt.org/page/BiteSizedTasks and linked from there.

Further enhancements could go a step further and create one function
(actually a macro the same way CheckError is done) and wrap those two
lines in one so that it is even shorter.  This, however, is not meant
to be part of this series.

Patches [3/4] and [4/4] utilize this for miscellaneous clean-ups in

Martin Kletzander (4):
  util: Umark virBufferCheckErrorInternal as ATTRIBUTE_RETURN_CHECK
  util: Use virBufferCheckError to its full potential.
  conf: Clean up and report error in virDomainCapsFormat
  conf: Clean up and report error in virDomainGenerateMachineName

 src/conf/domain_capabilities.c | 68 +++++++++++++++++-------------------------
 src/conf/domain_conf.c         | 16 +++++-----
 src/util/virbitmap.c           |  6 +---
 src/util/virbuffer.h           |  2 +-
 4 files changed, 37 insertions(+), 55 deletions(-)


More information about the libvir-list mailing list