<html>
<head>
<base href="https://bugs.freedesktop.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - amdgpu_bo_import and amdgpu_bo_free are not paired which leaks amdgpu_bo"
href="https://bugs.freedesktop.org/show_bug.cgi?id=108381">108381</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>amdgpu_bo_import and amdgpu_bo_free are not paired which leaks amdgpu_bo
</td>
</tr>
<tr>
<th>Product</th>
<td>Mesa
</td>
</tr>
<tr>
<th>Version</th>
<td>18.2
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux (All)
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>major
</td>
</tr>
<tr>
<th>Priority</th>
<td>medium
</td>
</tr>
<tr>
<th>Component</th>
<td>Drivers/Gallium/radeonsi
</td>
</tr>
<tr>
<th>Assignee</th>
<td>dri-devel@lists.freedesktop.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>zhangyong@lbesec.com
</td>
</tr>
<tr>
<th>QA Contact</th>
<td>dri-devel@lists.freedesktop.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=142039" name="attach_142039" title="sample code to reproduce the issue">attachment 142039</a> <a href="attachment.cgi?id=142039&action=edit" title="sample code to reproduce the issue">[details]</a></span>
sample code to reproduce the issue
amdgpu_bo is reference counted, libdrm expects the number of calls to
amdgpu_bo_import must be equal to amdgpu_bo_free.
When importing prime fd into mesa, amdgpu_bo_from_handle will be called, which
calls amdgpu_bo_import to get the unique handle (which in fact is a pointer to
amdgpu_bo), then wrapped into amdgpu_winsys_bo object.
The problem is amdgpu_winsys_bo is also reference counted, if one tries to
import the same prime fd for multiple times, amdgpu_bo_import will be called
for multiple times, but only one amdgpu_winsys_bo will be created, so
amdgpu_bo_free will be called for only once, eventually leaks memory.
I have attached a sample code to reproduce this issue.
a possible solution is to call amdgpu_bo_free after amdgpu_bo_import if
result.buf_handle can be found in ws->bo_export_table, which will balance the
number of calls to amdgpu_bo_import and amdgpu_bo_free.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are the assignee for the bug.</li>
</ul>
</body>
</html>