Patch from Thiago Rondon <maluco@mileniumnet.com.br>
authoraland <aland>
Wed, 7 Feb 2001 17:05:00 +0000 (17:05 +0000)
committeraland <aland>
Wed, 7 Feb 2001 17:05:00 +0000 (17:05 +0000)
Remove references to malloc() && malloc.h.  Replace with
references to rad_malloc()

18 files changed:
src/modules/rlm_acct_unique/rlm_acct_unique.c
src/modules/rlm_always/rlm_always.c
src/modules/rlm_attr_filter/rlm_attr_filter.c
src/modules/rlm_example/rlm_example.c
src/modules/rlm_fastusers/rlm_fastusers.c
src/modules/rlm_files/rlm_files.c
src/modules/rlm_krb5/rlm_krb5.c
src/modules/rlm_ldap/rlm_ldap.c
src/modules/rlm_pam/rlm_pam.c
src/modules/rlm_preprocess/rlm_preprocess.c
src/modules/rlm_radutmp/rlm_radutmp.c
src/modules/rlm_realm/rlm_realm.c
src/modules/rlm_sql/drivers/rlm_sql_iodbc/sql_iodbc.c
src/modules/rlm_sql/drivers/rlm_sql_oracle/sql_oracle.c
src/modules/rlm_sql/rlm_sql.c
src/modules/rlm_sql/sql.c
src/modules/rlm_sql/sql_module.c
src/modules/rlm_unix/rlm_unix.c

index e924274..1c1e6cb 100644 (file)
@@ -53,10 +53,8 @@ static CONF_PARSER module_config[] = {
 static void unique_add_attr(int dictattr) {
        struct unique_attr_list         *new;           
        
-       if((new = malloc(sizeof(struct unique_attr_list))) == NULL) {
-               radlog(L_ERR, "rlm_acct_unique:  out of memory");
-               exit(1);
-       }
+       new = rad_malloc(sizeof(struct unique_attr_list));
+
        memset((struct unique_attr_list *)new, 0, sizeof(unique_attr_list));
 
        /* Assign the attr to our new structure */
@@ -122,10 +120,7 @@ static int unique_instantiate(CONF_SECTION *conf, void **instance) {
        /*
         *  Set up a storage area for instance data
         */
-       if ((inst = malloc(sizeof(*inst))) == NULL) {
-               radlog(L_ERR, "rlm_acct_unique:  out of memory");
-               return -1;
-       }
+       inst = rad_malloc(sizeof(*inst));
        memset(inst, 0, sizeof(*inst));
        
        if (cf_section_parse(conf, module_config) < 0) {
index 2a7a96b..628c1e4 100644 (file)
@@ -106,11 +106,7 @@ static int always_instantiate(CONF_SECTION *conf, void **instance)
        /*
         *      Set up a storage area for instance data
         */
-       data = malloc(sizeof(*data));
-       if (!data) {
-               radlog(L_ERR, "rlm_always:  out of memory");
-               return -1;
-       }
+       data = rad_malloc(sizeof(*data));
        
        /*
         *      Copy the configuration into the instance data
index 2fb3419..4e4d421 100644 (file)
 #include       <fcntl.h>
 #include        <limits.h>
 
-#if HAVE_MALLOC_H
-#  include     <malloc.h>
-#endif
-
 #ifdef HAVE_REGEX_H
 #  include      <regex.h>
 #endif
@@ -189,11 +185,7 @@ static int attr_filter_instantiate(CONF_SECTION *conf, void **instance)
         struct attr_filter_instance *inst;
        int rcode;
 
-        inst = malloc(sizeof *inst);
-        if (!inst) {
-                radlog(L_ERR|L_CONS, "Out of memory\n");
-                return -1;
-        }
+        inst = rad_malloc(sizeof *inst);
 
         if (cf_section_parse(conf, module_config) < 0) {
                 free(inst);
index c08b628..2d418b7 100644 (file)
@@ -112,10 +112,7 @@ static int example_instantiate(CONF_SECTION *conf, void **instance)
        /*
         *      Set up a storage area for instance data
         */
-       data = malloc(sizeof(*data));
-       if (!data) {
-               return -1;
-       }
+       data = rad_malloc(sizeof(*data));
        
        /*
         *      Copy the configuration into the instance data
index fffb77c..9e4b9ae 100644 (file)
 #include       <fcntl.h>
 #include       <limits.h>
 
-#if HAVE_MALLOC_H
-#  include     <malloc.h>
-#endif
-
 #include       "radiusd.h"
 #include       "modules.h"
 
@@ -111,10 +107,9 @@ static int fastuser_buildhash(struct fastuser_instance *inst) {
         * Allocate space for hash table here
         */
        memsize = sizeof(PAIR_LIST *) * inst->hashsize;
-       if( (newhash = (PAIR_LIST **)malloc(memsize)) == NULL) {
-               radlog(L_ERR, "rlm_fastusers:  Can't build hashtable, out of memory!");
-               return -1;
-       }
+
+       newhash = (PAIR_LIST **) rad_malloc(memsize);
+
        memset((PAIR_LIST *)newhash, 0, memsize);
 
        /* Read acct_users */
@@ -494,11 +489,8 @@ static int fastuser_instantiate(CONF_SECTION *conf, void **instance)
 {
        struct fastuser_instance *inst=0;
 
-       inst = malloc(sizeof *inst);
-       if (!inst) {
-               radlog(L_ERR|L_CONS, "Out of memory\n");
-               return -1;
-       }
+       inst = rad_malloc(sizeof *inst);
+
        memset(inst, 0, sizeof(inst));
 
        if (cf_section_parse(conf, module_config) < 0) {
index 04ffb51..f347290 100644 (file)
@@ -36,10 +36,6 @@ static const char rcsid[] = "$Id$";
 #include       <fcntl.h>
 #include       <limits.h>
 
-#if HAVE_MALLOC_H
-#      include <malloc.h>
-#endif
-
 #include       "radiusd.h"
 #include       "modules.h"
 
@@ -224,11 +220,7 @@ static int file_instantiate(CONF_SECTION *conf, void **instance)
        struct file_instance *inst;
        int rcode;
 
-       inst = malloc(sizeof *inst);
-       if (!inst) {
-               radlog(L_ERR|L_CONS, "Out of memory\n");
-               return -1;
-       }
+       inst = rad_malloc(sizeof *inst);
 
        if (cf_section_parse(conf, module_config) < 0) {
                free(inst);
index 9b10d20..1868031 100644 (file)
@@ -32,10 +32,6 @@ static const char rcsid[] = "$Id$";
 #include       <stdlib.h>
 #include       <string.h>
 
-#if HAVE_MALLOC_H
-#  include     <malloc.h>
-#endif
-
 #include       "radiusd.h"
 #include       "modules.h"
 
@@ -49,11 +45,7 @@ static int krb5_instantiate(CONF_SECTION *conf, void **instance)
        int r;
        krb5_context *context;
 
-       context = malloc(sizeof(*context));
-        if (!context) {
-                radlog(L_ERR|L_CONS, "Out of memory\n");
-                return -1;
-        }
+       context = rad_malloc(sizeof(*context));
 
         if ((r = krb5_init_context(context)) ) {
                radlog(L_AUTH, "rlm_krb5: krb5_init failed: %s",
index 74022dc..593820e 100644 (file)
@@ -172,11 +172,8 @@ ldap_instantiate(CONF_SECTION * conf, void **instance)
 {
        ldap_instance  *inst;
 
-       inst = malloc(sizeof *inst);
-       if (!inst) {
-               radlog(L_ERR | L_CONS, "rlm_ldap: Out of memory\n");
-               return -1;
-       }
+       inst = rad_malloc(sizeof *inst);
+
        if (cf_section_parse(conf, module_config) < 0) {
                free(inst);
                return -1;
index 3c0bd8e..fb87841 100644 (file)
 
 #include       <security/pam_appl.h>
 
-#if HAVE_MALLOC_H
-#  include     <malloc.h>
-#endif
-
 #include       "radiusd.h"
 #include       "modules.h"
 
@@ -66,11 +62,7 @@ static int pam_instantiate(CONF_SECTION *conf, void **instance)
                return -1;
        }
 
-       data = malloc(sizeof(*data));
-       if (!data) {
-               radlog(L_ERR|L_CONS, "rlm_pam: Out of memory\n");
-               return -1;
-       }
+       data = rad_malloc(sizeof(*data));
 
        data->pam_auth_name = config.pam_auth_name;
        config.pam_auth_name = NULL;
@@ -120,8 +112,7 @@ static int PAM_conv (int num_msg,
   int size = sizeof(struct pam_response);
   my_PAM *pam_config = (my_PAM *) appdata_ptr;
   
-#define GET_MEM if (reply) realloc(reply, size); else reply = malloc(size); \
-  if (!reply) return PAM_CONV_ERR; \
+#define GET_MEM if (reply) realloc(reply, size); else reply = rad_malloc(size); \
   size += sizeof(struct pam_response)
 #define COPY_STRING(s) ((s) ? strdup(s) : NULL)
                                     
index 4fb933e..0798147 100644 (file)
@@ -35,10 +35,6 @@ static const char rcsid[] = "$Id$";
 #include       <string.h>
 #include       <ctype.h>
 
-#if HAVE_MALLOC_H
-#  include     <malloc.h>
-#endif
-
 #include       "radiusd.h"
 #include       "modules.h"
 
@@ -524,11 +520,7 @@ static int preprocess_instantiate(CONF_SECTION *conf, void **instance)
        /*
         *      Allocate room to put the module's instantiation data.
         */
-       data = (rlm_preprocess_t *) malloc(sizeof(*data));
-       if (!data) {
-               radlog(L_ERR|L_CONS, "Out of memory\n");
-               return -1;
-       }
+       data = (rlm_preprocess_t *) rad_malloc(sizeof(*data));
 
        /*
         *      Copy the configuration over to the instantiation.
@@ -597,8 +589,6 @@ static int preprocess_authorize(void *instance, REQUEST *request)
                                    data->ascend_channels_per_line);
        }
 
-       hints_setup(data->hints, request);
-       
        /*
         *      Note that we add the Request-Src-IP-Address to the request
         *      structure BEFORE checking huntgroup access.  This allows
@@ -607,6 +597,8 @@ static int preprocess_authorize(void *instance, REQUEST *request)
         */
        add_nas_attr(request);
 
+       hints_setup(data->hints, request);
+       
        if (huntgroup_access(data->huntgroups, request->packet->vps) != RLM_MODULE_OK) {
                radlog(L_AUTH, "No huntgroup access: [%s] (%s)",
                    request->username->strvalue,
@@ -630,13 +622,14 @@ static int preprocess_preaccounting(void *instance, REQUEST *request)
         *  authentication && accounting.
         */
        rad_mangle(data, request);
-       r = hints_setup(data->hints, request);
 
        /*
         *  Ensure that we log the NAS IP Address in the packet.
         */
        add_nas_attr(request);
 
+       r = hints_setup(data->hints, request);
+
        return r;
 }
 
index 46fca6b..c1fbb0c 100644 (file)
 
 #include "config.h"
 
-#if HAVE_MALLOC_H
-#  include <malloc.h>
-#endif
-
 #include       "radiusd.h"
 #include       "radutmp.h"
 #include       "modules.h"
@@ -479,13 +475,12 @@ static int radutmp_accounting(void *instance, REQUEST *request)
                if (r >= 0 &&  (status == PW_STATUS_START ||
                                status == PW_STATUS_ALIVE)) {
                        if (cache == NULL) {
-                          if ((cache = malloc(sizeof(NAS_PORT))) != NULL) {
-                                  cache->nasaddr = ut.nas_address;
-                                  cache->port = ut.nas_port;
-                                  cache->offset = off;
-                                  cache->next = inst->nas_port_list;
-                                  inst->nas_port_list = cache;
-                          }
+                          cache = rad_malloc(sizeof(NAS_PORT));
+                          cache->nasaddr = ut.nas_address;
+                          cache->port = ut.nas_port;
+                          cache->offset = off;
+                          cache->next = inst->nas_port_list;
+                          inst->nas_port_list = cache;
                        }
                        ut.type = P_LOGIN;
                        write(fd, &ut, sizeof(u));
index df4b54b..2780143 100644 (file)
@@ -229,11 +229,7 @@ static int realm_instantiate(CONF_SECTION *conf, void **instance)
         struct realm_config_t *inst;
 
         /* setup a storage area for instance data */
-        inst = malloc(sizeof(struct realm_config_t));
-        if(!inst) {
-               radlog(L_ERR|L_CONS, "Out of memory\n");
-              return -1;
-       }
+        inst = rad_malloc(sizeof(struct realm_config_t));
 
        if(cf_section_parse(conf, module_config) < 0) {
               free(inst);
index ac21aea..0b0142e 100644 (file)
@@ -22,10 +22,7 @@ SQLSOCK *sql_create_socket(SQL_INST *inst)
 {
        SQLSOCK *socket;
 
-       if((socket = malloc(sizeof(SQLSOCK))) == NULL) {
-               radlog(L_CONS|L_ERR, "sql_create_socket: no memory");
-               exit(1);
-       }
+       socket = rad_malloc(sizeof(SQLSOCK));
 
        if(SQLAllocEnv(&socket->env_handle) != SQL_SUCCESS) {
                radlog(L_CONS|L_ERR, "sql_create_socket: SQLAllocEnv failed:  %s", 
@@ -103,10 +100,7 @@ int sql_select_query(SQL_INST *inst, SQLSOCK *socket, char *querystr)
 
        numfields = sql_num_fields(socket);
 
-       if( (row = (char **)malloc(sizeof(char *) * numfields)) == NULL) {
-               radlog(L_ERR, "sql_select_query:  Out of memory!");
-               return -1;
-       }
+       row = (char **) rad_malloc(sizeof(char *) * numfields);
        memset(row, 0, (sizeof(char *) * (numfields))); 
        row[numfields-1] = NULL;
 
@@ -118,7 +112,7 @@ int sql_select_query(SQL_INST *inst, SQLSOCK *socket, char *querystr)
                /* 
                 * Allocate space for each column 
                 */
-               row[i-1] = (SQLCHAR*)malloc((int)len);
+               row[i-1] = (SQLCHAR*)rad_malloc((int)len);
 
                /*
                 * This makes me feel dirty, but, according to Microsoft, it works.
index 53a4b8e..bf80b11 100644 (file)
@@ -26,10 +26,7 @@ SQLSOCK *sql_create_socket(SQL_INST *inst)
 {
        SQLSOCK *socket;
 
-       if ((socket = malloc(sizeof(SQLSOCK))) == NULL) {
-               radlog(L_CONS|L_ERR, "sql_create_socket: no memory");
-               exit(1);
-       }
+       socket = rad_malloc(sizeof(SQLSOCK));
 
        if (OCIEnvCreate(&socket->env, OCI_DEFAULT, (dvoid *)0,
                (dvoid * (*)(dvoid *, size_t)) 0,
@@ -179,7 +176,7 @@ int sql_select_query(SQL_INST *inst, SQLSOCK *socket, char *querystr)
 
        /* DEBUG2("sql_select_query(): colcount=%d",colcount); */
 
-       rowdata=(char **)malloc(sizeof(char *) * (colcount+1) );
+       rowdata=(char **)rad_malloc(sizeof(char *) * (colcount+1) );
        memset(rowdata, 0, (sizeof(char *) * (colcount+1) ));
 
        for (y=1; y <= colcount; y++) {
@@ -220,7 +217,7 @@ int sql_select_query(SQL_INST *inst, SQLSOCK *socket, char *querystr)
                                        sql_error(socket));
                                return -1;
                        }
-                       rowdata[y-1]=malloc(dsize+1);
+                       rowdata[y-1]=rad_malloc(dsize+1);
                        break;
                case SQLT_DAT:
                case SQLT_INT:
@@ -229,7 +226,7 @@ int sql_select_query(SQL_INST *inst, SQLSOCK *socket, char *querystr)
                case SQLT_PDN:
                case SQLT_BIN:
                case SQLT_NUM:
-                       rowdata[y-1]=malloc(dsize+1);
+                       rowdata[y-1]=rad_malloc(dsize+1);
                        break;
                default:
                        dsize=0;
index f2b4534..78ed724 100644 (file)
@@ -120,25 +120,17 @@ rlm_sql_instantiate(CONF_SECTION * conf, void **instance)
 
        SQL_INST *inst;
 
-       if ((inst = malloc(sizeof(SQL_INST))) == NULL) {
-               radlog(L_ERR | L_CONS, "sql_instantiate:  no memory");
-               return -1;
-       }
+       inst = rad_malloc(sizeof(SQL_INST));
        memset(inst, 0, sizeof(SQL_INST));
-       if ((inst->config = malloc(sizeof(SQL_CONFIG))) == NULL) {
-               radlog(L_ERR | L_CONS, "sql_instantiate:  no memory");
-               free(inst);
-               return -1;
-       }
+
+       inst->config = rad_malloc(sizeof(SQL_CONFIG));
        memset(inst->config, 0, sizeof(SQL_CONFIG));
 
 #if HAVE_PTHREAD_H
-       inst->lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
-       if (inst->lock == NULL)
-               return -1;
+       inst->lock = (pthread_mutex_t *) rad_malloc(sizeof(pthread_mutex_t));
        pthread_mutex_init(inst->lock, NULL);
 
-       inst->notfull = (pthread_cond_t *) malloc(sizeof(pthread_cond_t));
+       inst->notfull = (pthread_cond_t *) rad_malloc(sizeof(pthread_cond_t));
        pthread_cond_init(inst->notfull, NULL);
 #endif
 
index 30d947b..08b1f46 100644 (file)
@@ -75,7 +75,7 @@ sql_init_socketpool(SQL_INST * inst)
                } else {
                        sqlsocket->id = i;
 #if HAVE_PTHREAD_H
-                       sqlsocket->semaphore = (sem_t *) malloc(sizeof(sem_t));
+                       sqlsocket->semaphore = (sem_t *) rad_malloc(sizeof(sem_t));
                        sem_init(sqlsocket->semaphore, 0, SQLSOCK_UNLOCKED);
 #else
                        sqlsocket->in_use = 0;
index 8ae0936..049475e 100644 (file)
@@ -44,10 +44,7 @@ sql_create_socket(SQL_INST * inst)
 
        SQLSOCK *sqlsocket;
 
-       if ((sqlsocket = malloc(sizeof(SQLSOCK))) == NULL) {
-               radlog(L_CONS | L_ERR, "sql_create_socket: no memory");
-               exit(1);
-       }
+       sqlsocket = rad_malloc(sizeof(SQLSOCK));
 
        mysql_init(&(sqlsocket->conn));
        if (!
index 9dd91ed..53e5b3d 100644 (file)
@@ -35,10 +35,6 @@ static const char rcsid[] = "$Id$";
 
 #include "config.h"
 
-#if HAVE_MALLOC_H
-#  include <malloc.h>
-#endif
-
 #if HAVE_SHADOW_H
 #  include     <shadow.h>
 #endif
@@ -175,10 +171,7 @@ static int unix_instantiate(CONF_SECTION *conf, void **instance)
        /*
         *      Allocate room for the instance.
         */
-       inst = *instance = malloc(sizeof(struct unix_instance));
-       if(!inst) {
-             return -1;
-       }
+       inst = *instance = rad_malloc(sizeof(struct unix_instance));
 
        /*
         *      Copy the configuration into the instance data