--- jmemansi.c.orig 1996-01-06 23:29:46.000000000 +0000 +++ jmemansi.c 2006-04-23 10:54:09.812108600 +0100 @@ -12,6 +12,8 @@ * is shoved onto the user. */ +#include + #define JPEG_INTERNALS #include "jinclude.h" #include "jpeglib.h" @@ -157,7 +159,13 @@ GLOBAL(long) jpeg_mem_init (j_common_ptr cinfo) { - return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ + long phys_size; + + if ((phys_size = sysconf(_SC_PHYS_PAGES)) == -1) + return DEFAULT_MAX_MEM; /* default for max_memory_to_use */ + if ((phys_size *= sysconf(_SC_PAGESIZE)) < 0) + return DEFAULT_MAX_MEM; + return (long) (phys_size * 0.95); } GLOBAL(void)