diff options
| author | Quentin Rameau <quinq@fifth.space> | 2016-09-01 13:46:19 +0200 | 
|---|---|---|
| committer | Markus Teich <markus.teich@stusta.mhn.de> | 2016-09-02 10:50:32 +0200 | 
| commit | 1f66885fbf36c726b7615060d3c98cbf74218d13 (patch) | |
| tree | 6efbc92aa7523c9d2cf1c846b606c7a0c64d2f3e | |
| parent | 137f0076c2986306109d637599b885bdaf92cd58 (diff) | |
| download | slock-1f66885fbf36c726b7615060d3c98cbf74218d13.tar.gz slock-1f66885fbf36c726b7615060d3c98cbf74218d13.tar.xz  | |
Add cleanup() to do free(locks) + XCloseDisplay()
| -rw-r--r-- | slock.c | 16 | 
1 files changed, 10 insertions, 6 deletions
@@ -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)  { @@ -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;  	} @@ -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) @@ -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;  }  | 
