From f28aa5f3ecbd729b53894d7e091db0dab1368ddc Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Thu, 7 Dec 2006 17:02:25 +0000 Subject: - Patch #92059 by Steven et al: added a memory check to garland/color.module. --- modules/color/color.module | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'modules') diff --git a/modules/color/color.module b/modules/color/color.module index f75f483eb..b6c43ef67 100644 --- a/modules/color/color.module +++ b/modules/color/color.module @@ -189,6 +189,23 @@ function color_scheme_form_submit($form_id, $values) { } } + // Make sure enough memory is available, if PHP's memory limit is compiled in. + if (function_exists('memory_get_usage')) { + // Fetch source image dimensions. + $source = drupal_get_path('theme', $theme) .'/'. $info['base_image']; + list($width, $height) = getimagesize($source); + + // We need at least a copy of the source and a target buffer of the same + // size (both at 32bpp). + $required = $width * $height * 8; + $usage = memory_get_usage(); + $limit = parse_size(ini_get('memory_limit')); + if ($usage + $required > $limit) { + drupal_set_message(t('There is not enough memory available to PHP to change this theme\'s color scheme. You need at least %size more. Check the PHP documentation for more information.', array('%size' => format_size($usage + $required - $limit), '%url' => 'http://www.php.net/manual/en/ini.core.php#ini.sect.resource-limits')), 'error'); + return; + } + } + // Delete old files foreach (variable_get('color_'. $theme .'_files', array()) as $file) { @unlink($file); -- cgit v1.2.3