diff options
-rw-r--r-- | slock.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -230,6 +230,13 @@ unlockscreen(Display *dpy, Lock *lock) | |||
230 | free(lock); | 230 | free(lock); |
231 | } | 231 | } |
232 | 232 | ||
233 | static void | ||
234 | cleanup(Display *dpy) | ||
235 | { | ||
236 | free(locks); | ||
237 | XCloseDisplay(dpy); | ||
238 | } | ||
239 | |||
233 | static Lock * | 240 | static Lock * |
234 | lockscreen(Display *dpy, int screen) | 241 | lockscreen(Display *dpy, int screen) |
235 | { | 242 | { |
@@ -349,8 +356,7 @@ main(int argc, char **argv) { | |||
349 | /* did we actually manage to lock anything? */ | 356 | /* did we actually manage to lock anything? */ |
350 | if (nlocks == 0) { | 357 | if (nlocks == 0) { |
351 | /* nothing to protect */ | 358 | /* nothing to protect */ |
352 | free(locks); | 359 | cleanup(dpy); |
353 | XCloseDisplay(dpy); | ||
354 | return 1; | 360 | return 1; |
355 | } | 361 | } |
356 | 362 | ||
@@ -358,8 +364,7 @@ main(int argc, char **argv) { | |||
358 | if (argc > 0) { | 364 | if (argc > 0) { |
359 | switch (fork()) { | 365 | switch (fork()) { |
360 | case -1: | 366 | case -1: |
361 | free(locks); | 367 | cleanup(dpy); |
362 | XCloseDisplay(dpy); | ||
363 | die("slock: fork failed: %s\n", strerror(errno)); | 368 | die("slock: fork failed: %s\n", strerror(errno)); |
364 | case 0: | 369 | case 0: |
365 | if (close(ConnectionNumber(dpy)) < 0) | 370 | if (close(ConnectionNumber(dpy)) < 0) |
@@ -382,8 +387,7 @@ main(int argc, char **argv) { | |||
382 | for (s = 0; s < nscreens; s++) | 387 | for (s = 0; s < nscreens; s++) |
383 | unlockscreen(dpy, locks[s]); | 388 | unlockscreen(dpy, locks[s]); |
384 | 389 | ||
385 | free(locks); | 390 | cleanup(dpy); |
386 | XCloseDisplay(dpy); | ||
387 | 391 | ||
388 | return 0; | 392 | return 0; |
389 | } | 393 | } |