<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - OCaml binding memory crash"
href="https://llvm.org/bugs/show_bug.cgi?id=31008">31008</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>OCaml binding memory crash
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>youngju.song@sf.snu.ac.kr
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>According to the manual
(<a href="https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html)'s">https://caml.inria.fr/pub/docs/manual-ocaml/intfc.html)'s</a> Rule 5, block must
be filled by direct assignment after "caml_alloc_small".
```
Rule 5 After a structured block (a block with tag less than No_scan_tag) is
allocated with the low-level functions, all fields of this block must be filled
with well-formed values before the next allocation operation. If the block has
been allocated with caml_alloc_small, filling is performed by direct assignment
to the fields of the block:
Field(v, n) = vn;
```
However, in the code below, there does not exist such assignment.
<a href="https://github.com/llvm-mirror/llvm/blob/master/bindings/ocaml">https://github.com/llvm-mirror/llvm/blob/master/bindings/ocaml</a>
/llvm/llvm_ocaml.c#L483
<a href="https://github.com/llvm-mirror/llvm/blob/master/bindings/ocaml/llvm/llvm_ocaml.c#L630">https://github.com/llvm-mirror/llvm/blob/master/bindings/ocaml/llvm/llvm_ocaml.c#L630</a>
This actually led to memory crash, and following patch solved it.
```
result = caml_alloc_small(1, 0);
+ Field(result,0) = Val_int(0);
Store_field(result, 0, caml_copy_string(C));
```</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>