From 9599119905026b070b21f7070c3a226da493670d Mon Sep 17 00:00:00 2001 From: Andrei Sarakeev Date: Tue, 17 Nov 2015 09:19:28 +0300 Subject: [PATCH] fix memory leak --- xrandr.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/xrandr.c b/xrandr.c index dcfdde0..d0b858e 100644 --- a/xrandr.c +++ b/xrandr.c @@ -3391,11 +3391,11 @@ main (int argc, char **argv) int nelements; int int_value; unsigned long ulong_value; - unsigned char *prop_data; + unsigned char *prop_data = NULL; int actual_format; unsigned long nitems, bytes_after; Atom actual_type; - XRRPropertyInfo *propinfo; + XRRPropertyInfo *propinfo = NULL; type = AnyPropertyType; @@ -3411,7 +3411,8 @@ main (int argc, char **argv) type = actual_type; format = actual_format; } - + XFree(prop_data); + XFree(propinfo); malloced_data = property_values_from_string (prop->value, type, actual_format, &nelements); @@ -3811,7 +3812,7 @@ main (int argc, char **argv) props = XRRListOutputProperties (dpy, output->output.xid, &nprop); for (j = 0; j < nprop; j++) { - unsigned char *prop; + unsigned char *prop = NULL; int actual_format; unsigned long nitems, bytes_after; Atom actual_type; @@ -3833,6 +3834,9 @@ main (int argc, char **argv) print_output_property(atom_name, actual_format, actual_type, nitems, prop); + XFree(atom_name); + XFree(prop); + if (propinfo->range && propinfo->num_values > 0) { printf ("\t\trange%s: ", @@ -3864,7 +3868,7 @@ main (int argc, char **argv) printf ("\n"); } - free(propinfo); + XFree(propinfo); } } @@ -3967,21 +3971,23 @@ main (int argc, char **argv) if (monitors) { int m, o; - + char *monitor_name; printf("Monitors: %d\n", monitors->n); for (m = 0; m < monitors->n; m++) { + monitor_name = XGetAtomName(dpy, monitors->monitors[m].name); printf (" %d: %s%s%s %d/%dx%d/%d+%d+%d ", m, monitors->monitors[m].automatic ? "+" : "", monitors->monitors[m].primary ? "*" : "", - XGetAtomName(dpy, monitors->monitors[m].name), + monitor_name, monitors->monitors[m].width, monitors->monitors[m].mwidth, monitors->monitors[m].height, monitors->monitors[m].mheight, monitors->monitors[m].x, monitors->monitors[m].y); + XFree(monitor_name); for (o = 0; o < monitors->monitors[m].noutput; o++) { output_t *output = find_output_by_xid(monitors->monitors[m].outputs[o]); if (output) -- 2.5.0