diff options
author | Dmitry V. Levin <ldv@strace.io> | 2023-12-14 08:00:00 +0000 |
---|---|---|
committer | Dmitry V. Levin <ldv@strace.io> | 2023-12-14 08:00:00 +0000 |
commit | 954234f0a477636eab751a6601d34bab1db41b0e (patch) | |
tree | 83403cf711c78b112e2738eb82b35d801cce18ee /modules | |
parent | 297f0b554e497e95c891fd6a77f7ac5591649f26 (diff) | |
download | pam-954234f0a477636eab751a6601d34bab1db41b0e.tar.gz pam-954234f0a477636eab751a6601d34bab1db41b0e.tar.bz2 pam-954234f0a477636eab751a6601d34bab1db41b0e.zip |
treewide: assume free(NULL) is no-op
The C standard guarantees that if the argument of free() is a null
pointer, no action occurs.
Diffstat (limited to 'modules')
-rw-r--r-- | modules/pam_filter/pam_filter.c | 3 | ||||
-rw-r--r-- | modules/pam_listfile/pam_listfile.c | 6 | ||||
-rw-r--r-- | modules/pam_namespace/argv_parse.c | 5 | ||||
-rw-r--r-- | modules/pam_stress/pam_stress.c | 6 | ||||
-rw-r--r-- | modules/pam_timestamp/hmac_openssl_wrapper.c | 4 | ||||
-rw-r--r-- | modules/pam_unix/pam_unix_auth.c | 3 | ||||
-rw-r--r-- | modules/pam_xauth/pam_xauth.c | 10 |
7 files changed, 13 insertions, 24 deletions
diff --git a/modules/pam_filter/pam_filter.c b/modules/pam_filter/pam_filter.c index a3c3bb24..72c3b480 100644 --- a/modules/pam_filter/pam_filter.c +++ b/modules/pam_filter/pam_filter.c @@ -238,8 +238,7 @@ static void free_evp(char *evp[]) if (evp) for (i=0; i<4; ++i) { - if (evp[i]) - free(evp[i]); + free(evp[i]); } free(evp); } diff --git a/modules/pam_listfile/pam_listfile.c b/modules/pam_listfile/pam_listfile.c index 5561b9ea..a01b5a8a 100644 --- a/modules/pam_listfile/pam_listfile.c +++ b/modules/pam_listfile/pam_listfile.c @@ -92,7 +92,7 @@ pam_sm_authenticate (pam_handle_t *pamh, int flags UNUSED, else if(!strcmp(myval,"fail")) onerr = PAM_SERVICE_ERR; else { - if (ifname) free (ifname); + free(ifname); return PAM_SERVICE_ERR; } else if(!strcmp(mybuf,"sense")) @@ -101,11 +101,11 @@ pam_sm_authenticate (pam_handle_t *pamh, int flags UNUSED, else if(!strcmp(myval,"deny")) sense=1; else { - if (ifname) free (ifname); + free(ifname); return onerr; } else if(!strcmp(mybuf,"file")) { - if (ifname) free (ifname); + free(ifname); ifname = malloc(strlen(myval)+1); if (!ifname) return PAM_BUF_ERR; diff --git a/modules/pam_namespace/argv_parse.c b/modules/pam_namespace/argv_parse.c index 7d418e05..fff93f4c 100644 --- a/modules/pam_namespace/argv_parse.c +++ b/modules/pam_namespace/argv_parse.c @@ -65,7 +65,7 @@ int argv_parse(const char *in_buf, int *ret_argc, char ***ret_argv) new_argv = realloc(argv, (max_argc+1)*sizeof(char *)); if (!new_argv) { - if (argv) free(argv); + free(argv); free(buf); return -1; } @@ -131,8 +131,7 @@ int argv_parse(const char *in_buf, int *ret_argc, char ***ret_argv) void argv_free(char **argv) { if (argv) { - if (*argv) - free(*argv); + free(*argv); free(argv); } } diff --git a/modules/pam_stress/pam_stress.c b/modules/pam_stress/pam_stress.c index b2c55586..d0f54016 100644 --- a/modules/pam_stress/pam_stress.c +++ b/modules/pam_stress/pam_stress.c @@ -476,10 +476,8 @@ int pam_sm_chauthtok(pam_handle_t *pamh, int flags, resp = NULL; retval = converse(pamh,i,pmsg,&resp); - if (txt) { - free(txt); - txt = NULL; /* clean up */ - } + free(txt); + txt = NULL; /* clean up */ if (retval != PAM_SUCCESS) { return retval; } diff --git a/modules/pam_timestamp/hmac_openssl_wrapper.c b/modules/pam_timestamp/hmac_openssl_wrapper.c index ac434377..a59a8de2 100644 --- a/modules/pam_timestamp/hmac_openssl_wrapper.c +++ b/modules/pam_timestamp/hmac_openssl_wrapper.c @@ -297,9 +297,7 @@ hmac_management(pam_handle_t *pamh, int debug, void **out, size_t *out_length, ret = PAM_SUCCESS; done: - if (hmac_message != NULL) { - free(hmac_message); - } + free(hmac_message); if (key != NULL) { pam_overwrite_n(key, key_length); free(key); diff --git a/modules/pam_unix/pam_unix_auth.c b/modules/pam_unix/pam_unix_auth.c index 4eccff8e..976699d4 100644 --- a/modules/pam_unix/pam_unix_auth.c +++ b/modules/pam_unix/pam_unix_auth.c @@ -86,8 +86,7 @@ do { \ static void setcred_free (pam_handle_t *pamh UNUSED, void *ptr, int err UNUSED) { - if (ptr) - free (ptr); + free (ptr); } int diff --git a/modules/pam_xauth/pam_xauth.c b/modules/pam_xauth/pam_xauth.c index bc8a3d74..d5e99c9f 100644 --- a/modules/pam_xauth/pam_xauth.c +++ b/modules/pam_xauth/pam_xauth.c @@ -197,9 +197,7 @@ run_coprocess(pam_handle_t *pamh, const char *input, char **output, tmp = realloc(buffer, buffer_size + i + 1); if (tmp == NULL) { /* Uh-oh, bail. */ - if (buffer != NULL) { - free(buffer); - } + free(buffer); close(opipe[0]); waitpid(child, NULL, 0); sigaction(SIGCHLD, &oldsa, NULL); /* restore old signal handler */ @@ -545,10 +543,8 @@ pam_sm_open_session (pam_handle_t *pamh, int flags UNUSED, char *t, *screen; size_t tlen, slen; /* Free the useless cookie string. */ - if (cookie != NULL) { - free(cookie); - cookie = NULL; - } + free(cookie); + cookie = NULL; /* Allocate enough space to hold an adjusted name. */ tlen = strlen(display) + LINE_MAX + 1; t = calloc(1, tlen); |