[hackers] [slock] Add cleanup() to do free(locks) + XCloseDisplay() || Quentin Rameau

From: <git_AT_suckless.org>
Date: Fri, 2 Sep 2016 11:49:05 +0200 (CEST)

commit 1f66885fbf36c726b7615060d3c98cbf74218d13
Author: Quentin Rameau <quinq_AT_fifth.space>
AuthorDate: Thu Sep 1 13:46:19 2016 +0200
Commit: Markus Teich <markus.teich_AT_stusta.mhn.de>
CommitDate: Fri Sep 2 10:50:32 2016 +0200

    Add cleanup() to do free(locks) + XCloseDisplay()

diff --git a/slock.c b/slock.c
index 9ec2f71..4980325 100644
--- a/slock.c
+++ b/slock.c
_AT_@ -230,6 +230,13 @@ unlockscreen(Display *dpy, Lock *lock)
         free(lock);
 }
 
+static void
+cleanup(Display *dpy)
+{
+ free(locks);
+ XCloseDisplay(dpy);
+}
+
 static Lock *
 lockscreen(Display *dpy, int screen)
 {
_AT_@ -349,8 +356,7 @@ main(int argc, char **argv) {
         /* did we actually manage to lock anything? */
         if (nlocks == 0) {
                 /* nothing to protect */
- free(locks);
- XCloseDisplay(dpy);
+ cleanup(dpy);
                 return 1;
         }
 
_AT_@ -358,8 +364,7 @@ main(int argc, char **argv) {
         if (argc > 0) {
                 switch (fork()) {
                 case -1:
- free(locks);
- XCloseDisplay(dpy);
+ cleanup(dpy);
                         die("slock: fork failed: %s\n", strerror(errno));
                 case 0:
                         if (close(ConnectionNumber(dpy)) < 0)
_AT_@ -382,8 +387,7 @@ main(int argc, char **argv) {
         for (s = 0; s < nscreens; s++)
                 unlockscreen(dpy, locks[s]);
 
- free(locks);
- XCloseDisplay(dpy);
+ cleanup(dpy);
 
         return 0;
 }
Received on Fri Sep 02 2016 - 11:49:05 CEST

This archive was generated by hypermail 2.3.0 : Fri Sep 02 2016 - 12:00:35 CEST