Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm assuming the above code is calling the C functions <code>malloc()</code> and <code>free()</code>...</p> <p>If 1st <code>malloc()</code> fails, you arrive at <code>dealloc_1</code> with whatever garbage is in <code>r11</code> and <code>r12</code> after returning from the <code>malloc()</code>.</p> <p>If 2nd <code>malloc()</code> fails, you arrive at <code>dealloc_1</code> with whatever garbage is in <code>r12</code> after returning from the <code>malloc()</code>.</p> <p>Therefore, you have to zero out <code>r11</code> and <code>r12</code> before doing the first allocation.</p> <p>Since this is 64-bit mode, all pointers/addresses and sizes are normally 64-bit. When you pass one of those to a function, it has to be 64-bit. So, <code>push dword 16</code> isn't quite right. It should be <code>push qword 16</code> instead. Likewise, when you are removing these parameters from the stack, you have to remove exactly as many bytes as you've put there, so <code>add rsp, 4</code> must change to <code>add rsp, 8</code>.</p> <p>Finally, I don't know which registers <code>malloc()</code> and <code>free()</code> preserve and which they don't. You may need to save and restore the so-called <code>volatile registers</code> (see your C compiler documentation). The same holds for the code not shown. It must preserve <code>r11</code> and <code>r12</code> so they can be used for deallocation. <strong>EDIT</strong>: And I'd check if it's the right way of passing parameters through the stack (again, see your compiler documentation).</p> <p><strong>EDIT</strong>: you're testing <code>r11</code> for 0 right before 2nd <code>free()</code>. It should be <code>r12</code>. But <code>free()</code> doesn't really mind receiving NULL pointers. So, these checks can be removed.</p> <p>Pay attention to your code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload