You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Konstantin Sharenkov <Ko...@enterra-inc.com> on 2006/03/24 05:58:21 UTC

Memory allocation checks. Veri big impact to stablility

Hello.

 

If I understand everything correctly the function apr_palloc and
apr_pcalloc can return NULL as result if there is no more memory
available.

These functions are widely being used within library but a lot of times
result of these functions not being checked 

 

like

If( *result*==NULL )

            return APR_ENOMEM.

 

 

It impacts to stability of software used apr, apr-pool under stress
load. Or withrestricted memory

 

Can you fix these cases in your libraries?

I think it is very important!!!!

 

I have made review some of cases

 

apr\atomic\unix\apr_atomic.c

 

   hash_mutex = apr_palloc(p, sizeof(apr_thread_mutex_t*) *
NUM_ATOMIC_HASH);

 

   for (i = 0; i < NUM_ATOMIC_HASH; i++) {

       rv = apr_thread_mutex_create(&(hash_mutex[i]),

                                    APR_THREAD_MUTEX_DEFAULT, p);

       if (rv != APR_SUCCESS) {

          return rv;

       }

   }

 

apr\file_io\os2\filedup.c

 

    *new_file = (apr_file_t *)apr_palloc(p, sizeof(apr_file_t));

    memcpy(*new_file, old_file, sizeof(apr_file_t));

    (*new_file)->pool = p;

 

 

        (*new_file)->buffer = apr_palloc(p, old_file->bufsize);

        (*new_file)->bufsize = old_file->bufsize;

 

apr\file_io\os2\open.c

 

    apr_file_t *dafile = (apr_file_t *)apr_palloc(pool,
sizeof(apr_file_t));

 

    dafile->pool = pool;

    dafile->isopen = FALSE;

 

 

    (*file) = apr_palloc(pool, sizeof(apr_file_t));

    (*file)->pool = pool;

    (*file)->filedes = *dafile;

 

 

        (*file)->buffer = apr_palloc(pool, APR_FILE_DEFAULT_BUFSIZE);

        (*file)->bufsize = APR_FILE_DEFAULT_BUFSIZE;

        rv = apr_thread_mutex_create(&(*file)->mutex, 0, pool);

 

apr\file_io\os2\pipe.c

 

 

    (*in) = (apr_file_t *)apr_palloc(pool, sizeof(apr_file_t));

    rc = DosCreateEventSem(NULL, &(*in)->pipeSem, DC_SEM_SHARED, FALSE);

 

 

    (*out) = (apr_file_t *)apr_palloc(pool, sizeof(apr_file_t));

    (*out)->pool = pool;

    (*out)->filedes = filedes[1];

 

 

apr\file_io\unix\dir.c

 

    (*new) = (apr_dir_t *)apr_palloc(pool, sizeof(apr_dir_t));

 

    (*new)->pool = pool;

 

 

..following only list of affected files

 

apr\file_io\unix\filedup.c

apr\file_io\unix\filepath.c

apr\file_io\unix\filepath_util.c

apr\file_io\unix\open.c

apr\file_io\win32\dir.c

apr\file_io\win32\filedup.c

apr\file_io\win32\filepath.c

apr\file_io\win32\open.c

apr\locks\os2\proc_mutex.c

apr\locks\os2\thread_mutex.c

apr\locks\os2\thread_rwlock.c

apr\locks\unix\global_mutex.c

apr\locks\unix\proc_mutex.c

apr\locks\unix\thread_cond.c

apr\locks\unix\thread_rwlock.c

apr\locks\win32\proc_mutex.c

apr\locks\win32\thread_cond.c

apr\locks\win32\thread_rwlock.c

apr\memory\unix\apr_pools.c

 

apr_pcallock affected!!!!!!!

APR_DECLARE(void *) apr_pcalloc(apr_pool_t *pool, apr_size_t size)

{

    void *mem;

 

    size = APR_ALIGN_DEFAULT(size);

    if ((mem = apr_palloc(pool, size)) != NULL) {

        memset(mem, 0, size); // ! there

    }

 

    return mem;

}

 

apr\misc\unix\env.c

 

...

Most all files !!! whre apr_palloc used!!!

 

 

With best regards 

Konstantin Sharenkov.

 

 

 


Re: Memory allocation checks. Veri big impact to stablility

Posted by Jeff Trawick <tr...@gmail.com>.
On 3/23/06, Konstantin Sharenkov <Ko...@enterra-inc.com> wrote:
>
> If I understand everything correctly the function apr_palloc and apr_pcalloc
> can return NULL as result if there is no more memory available.

if no abort function is registered

> These functions are widely being used within library but a lot of times
> result of these functions not being checked

when creating the pool, specify an abort function; see doc for
apr_pool_create_ex()