Project

General

Profile

Actions

Bug #15459

closed

Memory leak affecting ``lcdproc_client.php``, eventually hits PHP memory limit and crashes

Added by Jim Pingle 8 months ago. Updated 8 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
LCDProc
Target version:
-
Start date:
Due date:
% Done:

100%

Estimated time:
Plus Target Version:
Affected Version:
Affected Plus Version:
Affected Architecture:

Description

There is a memory leak affecting lcdproc_client.php leading it to eventually running out of RAM and dying with a PHP error:

PHP Fatal error:  Allowed memory size of 536870912 bytes exhausted (tried to allocate 8192 bytes) in /usr/local/pkg/lcdproc_client.php on line 856

The actual line varies from run to run.

Looking over the way the code is structured it has several potential issues where memory could be leaking though even after reworking the code and eliminating all of the issues I could identify there is still a slow leak.

A few things I was able to eliminate and identify:

  • It is not from reading/writing to the LCD socket or any file handles
  • It is not from keeping the LCD socket open
  • Forcing garbage collection doesn't help
  • Seems to leak 3808 bytes per loop even with no screens enabled.
  • Certain functions leak more than others. In particular:
    • With the Interfaces screen enabled the total amount leaked is 5600
    • With the output LEDs disabled, amount leaked goes down to 1904

Some of the leak appears to be in base, not the package, coming from get_interface_info(), specifically calls inside that:

  • get_interface_addresses() leaks about 2000 bytes
  • get_interface_ipv6() leaks about 800 bytes
  • get_interface_subnetv6() leaks about 800 bytes

Still investigating...

Actions #2

Updated by Jim Pingle 8 months ago

Drilling down into the affected functions above, they all call pfSense_get_ifaddrs() one or more (or many!) times and each time that function is called it appears to leak approximately 56 bytes of memory and on another similar system it leaks 112 bytes on most runs and 56 on others. I checked some other similar functions and they did not appear to leak anything (e.g. pfSense_getall_interface_addresses() does not leak).

Actions #3

Updated by Jim Pingle 8 months ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100

I made some optimizations to the LCDProc client code to help here but the memory leak issue is still the primary root cause as far as I've been able to determine so far.

Since the problem is in the pfSense PHP module and not LCDProc, I moved that over to a fresh issue at #15471 dedicated to just that problem.

Actions

Also available in: Atom PDF