database is loaded repetitively and exhausts memory
Brought to you by:
argos66
There is a problem where the cl_scanfile function will repetitively load the virus definition database over and over again if the load_db_on_startup ini is not set. If the ini is set, the php-clamav correctly loads the database only once.
Eventually, repeat calls to cl_scanfile will result in memory exhaustion due to the repetitive loading of the db.
To solve this, go into file clamav.c and change:
if (CLAMAV_G(load_db_on_startup) == 0) { if ((ret = clamav_load_database()) != CL_SUCCESS) { php_error(E_WARNING, "Load database during cl_scanfile failed : error : %i (%s)\n", ret, cl_strerror(ret)); RETURN_FALSE; } }
to this:
static int db_loaded = 0; if ((CLAMAV_G(load_db_on_startup) == 0) && (!db_loaded)) { if ((ret = clamav_load_database()) != CL_SUCCESS) { php_error(E_WARNING, "Load database during cl_scanfile failed : error : %i (%s)\n", ret, cl_strerror(ret)); RETURN_FALSE; }else{ db_loaded = 1; } }
And that will cause the database to be loaded only once in cases where load_db_on_startup ini is not set.
Thanks for your report.
I approve and commit your change soon.
Commit on svn, available into the next release.