Changeset 232 in openpam for trunk


Ignore:
Timestamp:
May 24, 2003, 7:44:29 PM (16 years ago)
Author:
Dag-Erling Smørgrav
Message:

With one single exception (where the pointer is obviously being
immediately overwritten), replace all use of free(3) with a macro
that clears the pointer after freeing the memory it pointed to.

Suggested by: Dmitry V. Levin <ldv@…>

Location:
trunk/lib
Files:
22 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/openpam_borrow_cred.c

    r224 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/openpam_borrow_cred.c#6 $
     34 * $P4: //depot/projects/openpam/lib/openpam_borrow_cred.c#7 $
    3535 */
    3636
     
    7878        r = getgroups(NGROUPS_MAX, scred->groups);
    7979        if (r == -1) {
    80                 free(scred);
     80                FREE(scred);
    8181                RETURNC(PAM_SYSTEM_ERR);
    8282        }
     
    8484        r = pam_set_data(pamh, PAM_SAVED_CRED, scred, &openpam_free_data);
    8585        if (r != PAM_SUCCESS) {
    86                 free(scred);
     86                FREE(scred);
    8787                RETURNC(r);
    8888        }
  • trunk/lib/openpam_configure.c

    r174 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/openpam_configure.c#6 $
     34 * $P4: //depot/projects/openpam/lib/openpam_configure.c#7 $
    3535 */
    3636
     
    239239                        r = openpam_read_policy_file(policy,
    240240                            service, filename, PAM_D_STYLE);
    241                         free(filename);
     241                        FREE(filename);
    242242                } else {
    243243                        r = openpam_read_policy_file(policy,
  • trunk/lib/openpam_dynamic.c

    r221 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/openpam_dynamic.c#9 $
     34 * $P4: //depot/projects/openpam/lib/openpam_dynamic.c#10 $
    3535 */
    3636
     
    7070                if ((dlh = dlopen(vpath, RTLD_LAZY)) == NULL) {
    7171                        openpam_log(PAM_LOG_DEBUG, "%s: %s", vpath, dlerror());
    72                         free(module);
     72                        FREE(module);
    7373                        return (NULL);
    7474                }
    7575        }
    76         free(vpath);
     76        FREE(vpath);
    7777        if ((module->path = strdup(path)) == NULL)
    7878                goto buf_err;
     
    8989        if (dlh != NULL)
    9090                dlclose(dlh);
    91         free(module);
     91        FREE(module);
    9292        return (NULL);
    9393}
  • trunk/lib/openpam_free_data.c

    r187 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/openpam_free_data.c#3 $
     34 * $P4: //depot/projects/openpam/lib/openpam_free_data.c#4 $
    3535 */
    3636
     
    5555        (void)pamh;
    5656        (void)status;
    57         free(data);
     57        FREE(data);
    5858        RETURNV();
    5959}
  • trunk/lib/openpam_impl.h

    r221 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/openpam_impl.h#22 $
     34 * $P4: //depot/projects/openpam/lib/openpam_impl.h#23 $
    3535 */
    3636
     
    125125pam_module_t   *openpam_dynamic(const char *);
    126126
     127#define FREE(p) do { free((p)); (p) = NULL; } while (0);
     128
    127129#ifdef DEBUG
    128130#define ENTER() openpam_log(PAM_LOG_DEBUG, "entering")
  • trunk/lib/openpam_load.c

    r184 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/openpam_load.c#15 $
     34 * $P4: //depot/projects/openpam/lib/openpam_load.c#16 $
    3535 */
    3636
     
    137137                modules = module->next;
    138138        openpam_log(PAM_LOG_DEBUG, "releasing %s", module->path);
    139         free(module->path);
    140         free(module);
     139        FREE(module->path);
     140        FREE(module);
    141141}
    142142
     
    155155        chain->next = NULL;
    156156        while (chain->optc--)
    157                 free(chain->optv[chain->optc]);
    158         free(chain->optv);
     157                FREE(chain->optv[chain->optc]);
     158        FREE(chain->optv);
    159159        openpam_release_module(chain->module);
    160         free(chain);
     160        FREE(chain);
    161161}
    162162
  • trunk/lib/openpam_log.c

    r229 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/openpam_log.c#21 $
     34 * $P4: //depot/projects/openpam/lib/openpam_log.c#22 $
    3535 */
    3636
     
    113113        if (asprintf(&format, "in %s(): %s", func, fmt) > 0) {
    114114                vsyslog(priority, format, ap);
    115                 free(format);
     115                FREE(format);
    116116        } else {
    117117                vsyslog(priority, fmt, ap);
  • trunk/lib/openpam_set_option.c

    r227 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/openpam_set_option.c#9 $
     34 * $P4: //depot/projects/openpam/lib/openpam_set_option.c#10 $
    3535 */
    3636
     
    9090                optv = realloc(cur->optv, sizeof(char *) * (cur->optc + 2));
    9191                if (optv == NULL) {
    92                         free(opt);
     92                        FREE(opt);
    9393                        RETURNC(PAM_BUF_ERR);
    9494                }
     
    9999        } else {
    100100                /* replace */
    101                 free(cur->optv[i]);
     101                FREE(cur->optv[i]);
    102102                cur->optv[i] = opt;
    103103        }
  • trunk/lib/openpam_ttyconv.c

    r227 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/openpam_ttyconv.c#17 $
     34 * $P4: //depot/projects/openpam/lib/openpam_ttyconv.c#18 $
    3535 */
    3636
     
    180180 fail:
    181181        while (i)
    182                 free(resp[--i]);
    183         free(*resp);
     182                FREE(resp[--i]);
     183        FREE(*resp);
    184184        *resp = NULL;
    185185        RETURNC(PAM_CONV_ERR);
     
    200200 *
    201201 * The =openpam_ttyconv function allows the application to specify a
    202  * timeout for user input by setting the global variable
     202 * timeout for user input by setting the global integer variable
    203203 * :openpam_ttyconv_timeout to the length of the timeout in seconds.
    204204 *
  • trunk/lib/pam_end.c

    r187 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_end.c#11 $
     34 * $P4: //depot/projects/openpam/lib/pam_end.c#12 $
    3535 */
    3636
     
    6464                        (dp->cleanup)(pamh, dp->data, status);
    6565                pamh->module_data = dp->next;
    66                 free(dp->name);
    67                 free(dp);
     66                FREE(dp->name);
     67                FREE(dp);
    6868        }
    6969
    7070        /* clear environment */
    7171        while (pamh->env_count)
    72                 free(pamh->env[--pamh->env_count]);
    73         free(pamh->env);
     72                FREE(pamh->env[--pamh->env_count]);
     73        FREE(pamh->env);
    7474
    7575        /* clear chains */
     
    8080                pam_set_item(pamh, i, NULL);
    8181
    82         free(pamh);
     82        FREE(pamh);
    8383
    8484        RETURNC(PAM_SUCCESS);
  • trunk/lib/pam_error.c

    r163 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_error.c#8 $
     34 * $P4: //depot/projects/openpam/lib/pam_error.c#9 $
    3535 */
    3636
     
    4141#include <security/pam_appl.h>
    4242#include <security/openpam.h>
     43
     44#include "openpam_impl.h"
    4345
    4446/*
     
    6062        r = pam_vprompt(pamh, PAM_ERROR_MSG, &rsp, fmt, ap);
    6163        va_end(ap);
    62         free(rsp); /* ignore response */
     64        FREE(rsp); /* ignore response */
    6365        return (r);
    6466}
  • trunk/lib/pam_get_authtok.c

    r221 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_get_authtok.c#22 $
     34 * $P4: //depot/projects/openpam/lib/pam_get_authtok.c#23 $
    3535 */
    3636
     
    110110                r = pam_prompt(pamh, style, &resp2, "Retype %s", prompt);
    111111                if (r != PAM_SUCCESS) {
    112                         free(resp);
     112                        FREE(resp);
    113113                        RETURNC(r);
    114114                }
    115115                if (strcmp(resp, resp2) != 0) {
    116                         free(resp);
     116                        FREE(resp);
    117117                        resp = NULL;
    118118                }
    119                 free(resp2);
     119                FREE(resp2);
    120120        }
    121121        if (resp == NULL)
    122122                RETURNC(PAM_TRY_AGAIN);
    123123        r = pam_set_item(pamh, item, resp);
    124         free(resp);
     124        FREE(resp);
    125125        if (r != PAM_SUCCESS)
    126126                RETURNC(r);
  • trunk/lib/pam_get_user.c

    r221 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_get_user.c#15 $
     34 * $P4: //depot/projects/openpam/lib/pam_get_user.c#16 $
    3535 */
    3636
     
    7676                RETURNC(r);
    7777        r = pam_set_item(pamh, PAM_USER, resp);
    78         free(resp);
     78        FREE(resp);
    7979        if (r != PAM_SUCCESS)
    8080                RETURNC(r);
  • trunk/lib/pam_getenvlist.c

    r187 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_getenvlist.c#10 $
     34 * $P4: //depot/projects/openpam/lib/pam_getenvlist.c#11 $
    3535 */
    3636
     
    6767                if ((envlist[i] = strdup(pamh->env[i])) == NULL) {
    6868                        while (i)
    69                                 free(envlist[--i]);
    70                         free(envlist);
     69                                FREE(envlist[--i]);
     70                        FREE(envlist);
    7171                        openpam_log(PAM_LOG_ERROR, "%s",
    7272                                pam_strerror(pamh, PAM_BUF_ERR));
  • trunk/lib/pam_info.c

    r157 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_info.c#7 $
     34 * $P4: //depot/projects/openpam/lib/pam_info.c#8 $
    3535 */
    3636
     
    4141#include <security/pam_appl.h>
    4242#include <security/openpam.h>
     43
     44#include "openpam_impl.h"
    4345
    4446/*
     
    6062        r = pam_vprompt(pamh, PAM_TEXT_INFO, &rsp, fmt, ap);
    6163        va_end(ap);
    62         free(rsp); /* ignore response */
     64        FREE(rsp); /* ignore response */
    6365        return (r);
    6466}
  • trunk/lib/pam_putenv.c

    r187 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_putenv.c#9 $
     34 * $P4: //depot/projects/openpam/lib/pam_putenv.c#10 $
    3535 */
    3636
     
    6868                if ((p = strdup(namevalue)) == NULL)
    6969                        RETURNC(PAM_BUF_ERR);
    70                 free(pamh->env[i]);
     70                FREE(pamh->env[i]);
    7171                pamh->env[i] = p;
    7272                RETURNC(PAM_SUCCESS);
  • trunk/lib/pam_set_data.c

    r221 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_set_data.c#13 $
     34 * $P4: //depot/projects/openpam/lib/pam_set_data.c#14 $
    3535 */
    3636
     
    7474                RETURNC(PAM_BUF_ERR);
    7575        if ((dp->name = strdup(module_data_name)) == NULL) {
    76                 free(dp);
     76                FREE(dp);
    7777                RETURNC(PAM_BUF_ERR);
    7878        }
  • trunk/lib/pam_set_item.c

    r221 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_set_item.c#19 $
     34 * $P4: //depot/projects/openpam/lib/pam_set_item.c#20 $
    3535 */
    3636
     
    9191        if (*slot != NULL) {
    9292                memset(*slot, 0xd0, osize);
    93                 free(*slot);
     93                FREE(*slot);
    9494        }
    9595        if (item != NULL) {
  • trunk/lib/pam_setenv.c

    r187 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_setenv.c#8 $
     34 * $P4: //depot/projects/openpam/lib/pam_setenv.c#9 $
    3535 */
    3636
     
    7676        sprintf(env, "%s=%s", name, value);
    7777        r = pam_putenv(pamh, env);
    78         free(env);
     78        FREE(env);
    7979        RETURNC(r);
    8080}
  • trunk/lib/pam_verror.c

    r157 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_verror.c#6 $
     34 * $P4: //depot/projects/openpam/lib/pam_verror.c#7 $
    3535 */
    3636
     
    4040#include <security/pam_appl.h>
    4141#include <security/openpam.h>
     42
     43#include "openpam_impl.h"
    4244
    4345/*
     
    5658
    5759        r = pam_vprompt(pamh, PAM_ERROR_MSG, &rsp, fmt, ap);
    58         free(rsp); /* ignore response */
     60        FREE(rsp); /* ignore response */
    5961        return (r);
    6062}
  • trunk/lib/pam_vinfo.c

    r157 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_vinfo.c#6 $
     34 * $P4: //depot/projects/openpam/lib/pam_vinfo.c#7 $
    3535 */
    3636
     
    4040#include <security/pam_appl.h>
    4141#include <security/openpam.h>
     42
     43#include "openpam_impl.h"
    4244
    4345/*
     
    5658
    5759        r = pam_vprompt(pamh, PAM_TEXT_INFO, &rsp, fmt, ap);
    58         free(rsp); /* ignore response */
     60        FREE(rsp); /* ignore response */
    5961        return (r);
    6062}
  • trunk/lib/pam_vprompt.c

    r221 r232  
    3232 * SUCH DAMAGE.
    3333 *
    34  * $P4: //depot/projects/openpam/lib/pam_vprompt.c#10 $
     34 * $P4: //depot/projects/openpam/lib/pam_vprompt.c#11 $
    3535 */
    3636
     
    7878        r = (conv->conv)(1, &msgp, &rsp, conv->appdata_ptr);
    7979        *resp = rsp == NULL ? NULL : rsp->resp;
    80         free(rsp);
     80        FREE(rsp);
    8181        RETURNC(r);
    8282}
Note: See TracChangeset for help on using the changeset viewer.