Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
do not check for NULL in FREE macro
Browse files Browse the repository at this point in the history
free(3) is safe to invoke on a NULL pointer, in which case no action is
taken. This change adjusts the FREE macros to omit this unnecessary
check.
  • Loading branch information
d-e-s-o committed Nov 23, 2017
1 parent 362cbe6 commit 865bd46
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 30 deletions.
10 changes: 4 additions & 6 deletions i3-config-wizard/main.c
Expand Up @@ -58,12 +58,10 @@
#error "SYSCONFDIR not defined"
#endif

#define FREE(pointer) \
do { \
if (pointer != NULL) { \
free(pointer); \
pointer = NULL; \
} \
#define FREE(pointer) \
do { \
free(pointer); \
pointer = NULL; \
} while (0)

#include "xcb.h"
Expand Down
10 changes: 4 additions & 6 deletions i3-input/i3-input.h
Expand Up @@ -5,12 +5,10 @@
#include <err.h>

#define die(...) errx(EXIT_FAILURE, __VA_ARGS__);
#define FREE(pointer) \
do { \
if (pointer != NULL) { \
free(pointer); \
pointer = NULL; \
} \
#define FREE(pointer) \
do { \
free(pointer); \
pointer = NULL; \
} while (0)

extern xcb_window_t root;
10 changes: 4 additions & 6 deletions i3-nagbar/i3-nagbar.h
Expand Up @@ -5,12 +5,10 @@
#include <err.h>

#define die(...) errx(EXIT_FAILURE, __VA_ARGS__);
#define FREE(pointer) \
do { \
if (pointer != NULL) { \
free(pointer); \
pointer = NULL; \
} \
#define FREE(pointer) \
do { \
free(pointer); \
pointer = NULL; \
} while (0)

#define xmacro(atom) xcb_atom_t A_##atom;
Expand Down
10 changes: 4 additions & 6 deletions i3bar/include/util.h
Expand Up @@ -20,12 +20,10 @@
#define STARTS_WITH(string, len, needle) (((len) >= strlen((needle))) && strncasecmp((string), (needle), strlen((needle))) == 0)

/* Securely free p */
#define FREE(p) \
do { \
if (p != NULL) { \
free(p); \
p = NULL; \
} \
#define FREE(p) \
do { \
free(p); \
p = NULL; \
} while (0)

/* Securely free single-linked list */
Expand Down
10 changes: 4 additions & 6 deletions include/util.h
Expand Up @@ -47,12 +47,10 @@
break; \
}

#define FREE(pointer) \
do { \
if (pointer != NULL) { \
free(pointer); \
pointer = NULL; \
} \
#define FREE(pointer) \
do { \
free(pointer); \
pointer = NULL; \
} while (0)

#define CALL(obj, member, ...) obj->member(obj, ##__VA_ARGS__)
Expand Down

0 comments on commit 865bd46

Please sign in to comment.