magento-lts
magento-lts copied to clipboard
memory leak when resizing multiple product images
I've stumbled into this issue a while back and noted this from somewhere on the internet. Unfortunately I don't have the link anymore.
The issue is that when you loop through products and resize their main image you will at some point run out of memory. It seems the GD adapter is not freeing up memory correctly with it's custom shutdown function.
In my sites I used to override the adapter locally and it worked OK so I'm sharing the code I found. I'm not sure if you want to merge it though as it may interfere in other areas.
It will be good to have it noted down here anyways as a record that this problem exists and has a solution. Credits go to unknown person that wrote this down
Thanks for the PR!
Any other opinions to move this forward?
In this stackoverflow, there is a discussion about this issue. Someone commented about security concern with the __destruct()
method.
Interesting comments on Stackoverflow. The concern about security is coming from Magento Senior Piotr Kaminski. I would prefer the last solution offered in that post by logging the error too. It is implemented here:
https://github.com/sitewards/import_image_memory_leak_fix
To prevent security issues around serialization we could:
- disable serialization for this class
- make sure unserialization is safe (implementing e.g. __sleep and __wakeup) But to be honest, we solved serialization issues by implementing "allowed classes" everywhere where magento unserializes data, didn't we?
Yeah I'm failing to see how this code could pose a security risk.. especially with "allowed classes".