Re: [libvirt] [PATCH v1 27/32] util: perf: use VIR_AUTOFREE instead of VIR_FREE for scalar types

2018-08-06 Thread Erik Skultety
On Sat, Jul 28, 2018 at 11:31:42PM +0530, Sukrit Bhatnagar wrote:
> By making use of GNU C's cleanup attribute handled by the
> VIR_AUTOFREE macro for declaring scalar variables, majority
> of the VIR_FREE calls can be dropped, which in turn leads to
> getting rid of most of our cleanup sections.
>
> Signed-off-by: Sukrit Bhatnagar 
> ---
>  src/util/virperf.c | 17 +
>  1 file changed, 5 insertions(+), 12 deletions(-)
>
> diff --git a/src/util/virperf.c b/src/util/virperf.c
> index 4537cd0..1203a6e 100644
> --- a/src/util/virperf.c
> +++ b/src/util/virperf.c
> @@ -175,12 +175,12 @@ typedef struct virPerfEventAttr *virPerfEventAttrPtr;
>  static int
>  virPerfRdtAttrInit(void)
>  {
> -char *buf = NULL;
> +VIR_AUTOFREE(char *) buf = NULL;

I'll move this at the end of the declaration block.

Reviewed-by: Erik Skultety 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


[libvirt] [PATCH v1 27/32] util: perf: use VIR_AUTOFREE instead of VIR_FREE for scalar types

2018-07-28 Thread Sukrit Bhatnagar
By making use of GNU C's cleanup attribute handled by the
VIR_AUTOFREE macro for declaring scalar variables, majority
of the VIR_FREE calls can be dropped, which in turn leads to
getting rid of most of our cleanup sections.

Signed-off-by: Sukrit Bhatnagar 
---
 src/util/virperf.c | 17 +
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/src/util/virperf.c b/src/util/virperf.c
index 4537cd0..1203a6e 100644
--- a/src/util/virperf.c
+++ b/src/util/virperf.c
@@ -175,12 +175,12 @@ typedef struct virPerfEventAttr *virPerfEventAttrPtr;
 static int
 virPerfRdtAttrInit(void)
 {
-char *buf = NULL;
+VIR_AUTOFREE(char *) buf = NULL;
 char *tmp = NULL;
 unsigned int attr_type = 0;
 
 if (virFileReadAllQuiet("/sys/devices/intel_cqm/type", 10, &buf) < 0)
-goto error;
+return -1;
 
 if ((tmp = strchr(buf, '\n')))
 *tmp = '\0';
@@ -188,19 +188,14 @@ virPerfRdtAttrInit(void)
 if (virStrToLong_ui(buf, NULL, 10, &attr_type) < 0) {
 virReportSystemError(errno, "%s",
  _("failed to get rdt event type"));
-goto error;
+return -1;
 }
-VIR_FREE(buf);
 
 attrs[VIR_PERF_EVENT_CMT].attrType = attr_type;
 attrs[VIR_PERF_EVENT_MBMT].attrType = attr_type;
 attrs[VIR_PERF_EVENT_MBML].attrType = attr_type;
 
 return 0;
-
- error:
-VIR_FREE(buf);
-return -1;
 }
 
 
@@ -209,7 +204,6 @@ virPerfEventEnable(virPerfPtr perf,
virPerfEventType type,
pid_t pid)
 {
-char *buf = NULL;
 struct perf_event_attr attr;
 virPerfEventPtr event = &(perf->events[type]);
 virPerfEventAttrPtr event_attr = &attrs[type];
@@ -227,6 +221,8 @@ virPerfEventEnable(virPerfPtr perf,
 }
 
 if (type == VIR_PERF_EVENT_CMT) {
+VIR_AUTOFREE(char *) buf = NULL;
+
 if (virFileReadAll("/sys/devices/intel_cqm/events/llc_occupancy.scale",
10, &buf) < 0)
 goto error;
@@ -236,8 +232,6 @@ virPerfEventEnable(virPerfPtr perf,
  _("failed to get cmt scaling factor"));
 goto error;
 }
-
-VIR_FREE(buf);
 }
 
 memset(&attr, 0, sizeof(attr));
@@ -268,7 +262,6 @@ virPerfEventEnable(virPerfPtr perf,
 
  error:
 VIR_FORCE_CLOSE(event->fd);
-VIR_FREE(buf);
 return -1;
 }
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list