Bug#909741: mesa-opencl-icd: Memory leak in clEnqueueNDRangeKernel()

2018-09-27 Thread David Kuehling
Note that this bug seems to be present in all versions of mesa 18.1.x [1]
but is fixed in mesa 18.2 [2].

[1] 
https://gitlab.freedesktop.org/mesa/mesa/blob/18.1/src/gallium/state_trackers/clover/core/kernel.hpp
[2] 
https://gitlab.freedesktop.org/mesa/mesa/blob/18.2/src/gallium/state_trackers/clover/core/kernel.hpp



Bug#909741: mesa-opencl-icd: Memory leak in clEnqueueNDRangeKernel()

2018-09-27 Thread David Kuehling
Package: mesa-opencl-icd
Version: 18.1.6-1~bpo9+1
Severity: normal

Dear Maintainer,

the mesa 18.1.6 version that is provided via debian-backports has a
memory leak in the functions that implement clEnqueueNDRangeKernel().

The root cause is that destructor
clover::kernel::scalar_argument::~scalar_argument() is never called, as
life-time is managed via a unique_ptr<> to the parent class 'argument'
which does not have a virtual destructor.  This leads to memory
allocated by member vector<> kernel::scalar_argument::_v to leak.

For me adding a virtual destructor fixes this specific leak:

--- src.orig/mesa-18.1.6/src/gallium/state_trackers/clover/core/kernel.hpp  
2018-08-13 18:42:38.0 +0200
+++ mesa-18.1.6/src/gallium/state_trackers/clover/core/kernel.hpp   
2018-09-27 10:17:16.689585453 +0200
@@ -75,6 +75,7 @@
  argument(const argument ) = delete;
  argument &
  operator=(const argument ) = delete;
+ virtual ~argument() = default;
 
  /// \a true if the argument has been set.
  bool set() const;

Maybe somebody more familiar with the sources could look through GCC
warnings or sanitizer output for whether more problems of that sort are
present throughout the Mesa sources?

This bug currently causes leela zero [1] to consume many gigabytes of
memory over time, making it impractical to run, see the corresponding
leela zero bug [2] ([2] also has more details like valgrind backtraces
of the leak in question).

cheers,

David

[1] http://zero.sjeng.org/
[2] https://github.com/gcp/leela-zero/issues/1823

-- Package-specific info:
glxinfo:

DISPLAY is not set.

X server symlink status:

lrwxrwxrwx 1 root root 13 Mar 22  2016 /etc/X11/X -> /usr/bin/Xorg
-rwxr-xr-x 1 root root 274 Oct 14  2017 /usr/bin/Xorg

VGA-compatible devices on PCI bus:
--
00:01.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. 
[AMD/ATI] Carrizo [1002:9874] (rev e3)

/etc/X11/xorg.conf does not exist.

/etc/X11/xorg.conf.d does not exist.

/etc/modprobe.d contains no KMS configuration files.

Kernel version (/proc/version):
---
Linux version 4.17.0-0.bpo.3-amd64 (debian-ker...@lists.debian.org) (gcc 
version 6.3.0 20170516 (Debian 6.3.0-18+deb9u1)) #1 SMP Debian 4.17.17-1~bpo9+1 
(2018-08-27)

Xorg X server log files on system:
--
-rw-r--r-- 1 root root 32159 Mar 22  2016 /var/log/Xorg.1.log
-rw-r--r-- 1 root root 36921 Sep  5 21:54 /var/log/Xorg.0.log

Contents of most recent Xorg X server log file (/var/log/Xorg.0.log):
-
[   641.716] 
X.Org X Server 1.19.2
Release Date: 2017-03-02
[   641.716] X Protocol Version 11, Revision 0
[   641.716] Build Operating System: Linux 4.9.0-4-amd64 x86_64 Debian
[   641.716] Current Operating System: Linux mosquito2 4.17.0-0.bpo.3-amd64 #1 
SMP Debian 4.17.17-1~bpo9+1 (2018-08-27) x86_64
[   641.716] Kernel command line: BOOT_IMAGE=/vmlinuz-4.17.0-0.bpo.3-amd64 
root=/dev/mapper/yami-root ro quiet
[   641.716] Build Date: 16 October 2017  08:19:45AM
[   641.716] xorg-server 2:1.19.2-1+deb9u2 (https://www.debian.org/support) 
[   641.716] Current version of pixman: 0.34.0
[   641.716]Before reporting problems, check http://wiki.x.org
to make sure that you have the latest version.
[   641.716] Markers: (--) probed, (**) from config file, (==) default setting,
(++) from command line, (!!) notice, (II) informational,
(WW) warning, (EE) error, (NI) not implemented, (??) unknown.
[   641.716] (==) Log file: "/var/log/Xorg.0.log", Time: Sat Sep  1 06:24:09 
2018
[   641.807] (==) Using system config directory "/usr/share/X11/xorg.conf.d"
[   641.973] (==) No Layout section.  Using the first Screen section.
[   641.973] (==) No screen section available. Using defaults.
[   641.973] (**) |-->Screen "Default Screen Section" (0)
[   641.973] (**) |   |-->Monitor ""
[   641.977] (==) No monitor specified for screen "Default Screen Section".
Using a default monitor configuration.
[   641.977] (==) Automatically adding devices
[   641.977] (==) Automatically enabling devices
[   641.977] (==) Automatically adding GPU devices
[   641.977] (==) Max clients allowed: 256, resource mask: 0x1f
[   642.044] (WW) The directory "/usr/share/fonts/X11/cyrillic" does not exist.
[   642.044]Entry deleted from font path.
[   642.231] (==) FontPath set to:
/usr/share/fonts/X11/misc,
/usr/share/fonts/X11/100dpi/:unscaled,
/usr/share/fonts/X11/75dpi/:unscaled,
/usr/share/fonts/X11/Type1,
/usr/share/fonts/X11/100dpi,
/usr/share/fonts/X11/75dpi,
built-ins
[   642.231] (==) ModulePath set to "/usr/lib/xorg/modules"
[   642.231] (II) The server relies on udev to provide the list of input 
devices.
If no devices become available, reconfigure udev or disable