Xinqi Bao's Git
projects
/
slock.git
/ diff
summary
|
log
|
commit
|
diff
|
tree
raw
|
patch
|
inline
| side by side (parent:
137f007
)
Add cleanup() to do free(locks) + XCloseDisplay()
author
Quentin Rameau <
[email protected]
>
Thu, 1 Sep 2016 11:46:19 +0000
(13:46 +0200)
committer
Markus Teich <
[email protected]
>
Fri, 2 Sep 2016 08:50:32 +0000
(10:50 +0200)
slock.c
diff
|
blob
|
history
diff --git
a/slock.c
b/slock.c
index
9ec2f71
..
4980325
100644
(file)
--- a/
slock.c
+++ b/
slock.c
@@
-230,6
+230,13
@@
unlockscreen(Display *dpy, Lock *lock)
free(lock);
}
free(lock);
}
+static void
+cleanup(Display *dpy)
+{
+ free(locks);
+ XCloseDisplay(dpy);
+}
+
static Lock *
lockscreen(Display *dpy, int screen)
{
static Lock *
lockscreen(Display *dpy, int screen)
{
@@
-349,8
+356,7
@@
main(int argc, char **argv) {
/* did we actually manage to lock anything? */
if (nlocks == 0) {
/* nothing to protect */
/* did we actually manage to lock anything? */
if (nlocks == 0) {
/* nothing to protect */
- free(locks);
- XCloseDisplay(dpy);
+ cleanup(dpy);
return 1;
}
return 1;
}
@@
-358,8
+364,7
@@
main(int argc, char **argv) {
if (argc > 0) {
switch (fork()) {
case -1:
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)
die("slock: fork failed: %s\n", strerror(errno));
case 0:
if (close(ConnectionNumber(dpy)) < 0)
@@
-382,8
+387,7
@@
main(int argc, char **argv) {
for (s = 0; s < nscreens; s++)
unlockscreen(dpy, locks[s]);
for (s = 0; s < nscreens; s++)
unlockscreen(dpy, locks[s]);
- free(locks);
- XCloseDisplay(dpy);
+ cleanup(dpy);
return 0;
}
return 0;
}