Beispiel #1
0
void* SecureRealloc(void *ptr, size_t size)
{
    void* handle;

#ifdef CLB_MEMORY_DEBUG
    secure_realloc_count++;
    if(ptr && !size)
    {
        secure_realloc_f_count++;
    }
    else if(!ptr && size)
    {
        secure_realloc_m_count++;
    }
#endif
    /* SunOS realloc() is broken, so here is a stupid workaround...*/

    handle = ptr?realloc(ptr,size):malloc(size);
    if(!handle && size!=0)
    {
        MemIsLow = true;
        MemFlushFreeList();
        handle = ptr?realloc(ptr,size):malloc(size);
        if(!handle)
        {   /*  Still nothing...*/
#ifdef PRINT_SOMEERRORS_STDOUT
            SetMemoryLimit(RLIM_INFINITY);
            fprintf(stdout, "# Failure: Resource limit exceeded (memory)\n");
            fflush(stdout);
            PrintRusage(stdout);
#endif
            Error("Out of Memory", OUT_OF_MEMORY);
        }
    }
#ifdef CLB_MEMORY_DEBUG2
    if(ptr != handle)
    {
        if(ptr)
        {
            printf("\nBlock %p F:\n", ptr);
        }
        printf("\nBlock %p R: %zd\n" ,handle, size);
    }
#endif

    return handle;
}
Beispiel #2
0
void ConfigureSystemSettings()
{
    int         memLimitPerc;
    uint64_t    memLimit;

    // percentage of physical memory can be used by the program
    memLimitPerc = configFile.GetIntValue("system.memoryLimitPercentage", 90);
    if (memLimitPerc < 0)
        memLimitPerc = 90;
    
    // memoryLimit overrides memoryLimitPercentage
    memLimit = configFile.GetInt64Value("system.memoryLimit", 0);
    if (memLimit == 0)
        memLimit = (uint64_t) (GetTotalPhysicalMemory() * memLimit / 100.0 + 0.5);

    if (memLimit != 0)
        SetMemoryLimit(memLimit);
}
Beispiel #3
0
void* SecureMalloc(size_t size)
{
    void* handle;

#ifdef CLB_MEMORY_DEBUG
    secure_malloc_count++;
    secure_malloc_mem += size;
#endif

    handle = (void*)malloc(size);

    if(!handle)
    {   /* malloc has no memory left  */
        MemIsLow = true;
        MemFlushFreeList(); /* Return own freelist */

        handle = (void*)malloc(size);

        if(!handle)
        {   /*  Still nothing...*/
#ifdef PRINT_SOMEERRORS_STDOUT
            SetMemoryLimit(RLIM_INFINITY);
            fprintf(stdout, "# Failure: Resource limit exceeded (memory)\n");
            TSTPOUT(stdout, "ResourceOut");
            fflush(stdout);
            PrintRusage(stdout);
#endif
            Error("Out of Memory", OUT_OF_MEMORY);
        }
    }
#ifdef CLB_MEMORY_DEBUG2
    printf("\nBlock %p M: %zd\n", handle, size);
#endif

    return handle;
}