{"componentChunkName":"component---src-templates-post-template-js","path":"/magical-windbg-vol1-06-en","result":{"data":{"markdownRemark":{"id":"f7519ccd-31fc-5be6-a2ff-cc881cd8a94a","html":"<blockquote>\n<p>This page has been machine-translated from the <a href=\"/magical-windbg-vol1-06\">original page</a>.</p>\n</blockquote>\n<p>In Chapters 4 and 5, we investigated the causes of process and system crashes using application crash dumps and full memory dumps.</p>\n<p>As we have seen in the chapters so far, dump files normally contain information about the exception that caused the crash when the dump was created.</p>\n<p>For that reason, by looking at the exception information recorded at dump creation with commands such as <code class=\"language-text\">!analyze -v</code>, it is relatively easy to identify the direct cause of a crash (the exception).</p>\n<p>However, when you investigate the cause of a problem other than a crash from a dump file, the exception information collected when the dump was created is no longer helpful, so the analysis becomes a little more difficult.</p>\n<p>In Chapters 6 and 7, we will use a user-mode application memory leak as an example of investigating a non-crash problem from a dump file.</p>\n<p>In this chapter, we will analyze a process dump from an application that is causing a memory leak.</p>\n<!-- omit in toc -->\n<h2 id=\"table-of-contents\" style=\"position:relative;\"><a href=\"#table-of-contents\" aria-label=\"table of contents permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Table of contents</h2>\n<ul>\n<li><a href=\"#reproducing-the-memory-leak-issue\">Reproducing the memory leak issue</a></li>\n<li><a href=\"#obtaining-a-process-dump\">Obtaining a process dump</a></li>\n<li><a href=\"#examining-the-exception-code-in-the-process-dump\">Examining the exception code in the process dump</a></li>\n<li><a href=\"#preparation-before-investigating-the-memory-leak-in-the-dump-file\">Preparation before investigating the memory leak in the dump file</a></li>\n<li><a href=\"#investigating-the-heap-region-in-the-process-dump\">Investigating the Heap region in the process dump</a></li>\n<li><a href=\"#identifying-the-code-responsible-for-the-memory-leak\">Identifying the code responsible for the memory leak</a></li>\n<li><a href=\"#analyzing-what-each-thread-is-doing\">Analyzing what each thread is doing</a></li>\n<li><a href=\"#summary-of-chapter-6\">Summary of Chapter 6</a></li>\n<li><a href=\"#links-to-each-chapter\">Links to each chapter</a></li>\n</ul>\n<h2 id=\"reproducing-the-memory-leak-issue\" style=\"position:relative;\"><a href=\"#reproducing-the-memory-leak-issue\" aria-label=\"reproducing the memory leak issue permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Reproducing the memory leak issue</h2>\n<p>First, let’s trigger the memory leak so that we can obtain the process dump to analyze.</p>\n<p>As in the previous chapters, we will use <code class=\"language-text\">D4C.exe</code> to reproduce the problem.</p>\n<p>Start <code class=\"language-text\">D4C.exe</code>, then enter <code class=\"language-text\">2</code> at the first menu to begin reproducing the memory leak issue.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/c9686e0bd856e304ccbd48f263c244c5/0b533/mem-leak-001.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 76.66666666666666%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACNklEQVQ4y42TS2/TQBSFDUpC4lect+147PEj8atpRSR+E2wRC1YsCGxb/gYgiEARXVAoISqs+UeHO5OkhLaBLo6uc618PufeGWX++Rvmi094+2Eh9Wb+Ea9J7xenOPt+gS+rH7Jun7+ufu6I3i0vcHq2xPlyhXfnv6D0XQ+9ThtqowFdU2HquqxN04CmUk+lnqFLqY06atXKddVqqNxR8OjpSyjBKEORZzg4mKAoSlKBsiwxnU7lc5pmyKn2+31YlgXDMG6QCa1ew+Pnr6DYjMNzXQQBx3A4BPMZHMdBFEXyt+d5Us1mEyq51UWCazKg3quugXFWggcBAQMkSUKgGGEYYjweYzAYoNvtoiHGsfmzpml7gJU1MDu8j/EoQZbnmEwmyKmKmL7vy5hb6M2gK8DZCZQwzRGRI89jEuJSXOGW0wjsgY1WqwXTNG8BFJFPxFJSxDQvRkAxR2/oSbD4iIi+G1lA90feAPkG6DMfnHO5AOFQ9MQH2u32JWS/y12HycYhYxIkNivA256IfOulzGgpUVZQPH4JFA5deYzIZRzDtm3pUpy3fzsk4AsCjsoJQr4GCajj2LIKpxa5E+dPQP8PrK637FPkhJyIRYglSKcUWZ5J6nd7PdTr9T+Rr0j2je0Mj2mG8QhJGMAnh5ygzHVkTaIQAfPQtprQ6A7r8l7vEd19tXoXT2YE5EcPEJdHcJMMLC3gxCnYuEBYHMIb5bBcH2rHhtZ1SPbf6mxE71SzhYfPjvEbvIqsR9VDrFUAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/c9686e0bd856e304ccbd48f263c244c5/8ac56/mem-leak-001.webp 240w,\n/static/c9686e0bd856e304ccbd48f263c244c5/d3be9/mem-leak-001.webp 480w,\n/static/c9686e0bd856e304ccbd48f263c244c5/b0a15/mem-leak-001.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/c9686e0bd856e304ccbd48f263c244c5/8ff5a/mem-leak-001.png 240w,\n/static/c9686e0bd856e304ccbd48f263c244c5/e85cb/mem-leak-001.png 480w,\n/static/c9686e0bd856e304ccbd48f263c244c5/0b533/mem-leak-001.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/c9686e0bd856e304ccbd48f263c244c5/0b533/mem-leak-001.png\"\n            alt=\"Reproducing a user-mode memory leak with D4C.exe\"\n            title=\"Reproducing a user-mode memory leak with D4C.exe\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Once execution begins, private memory for the <code class=\"language-text\">D4C.exe</code> process is allocated one after another, causing the process’s virtual memory<sup id=\"fnref-1\"><a href=\"#fn-1\" class=\"footnote-ref\">1</a></sup> space to keep growing due to the leak.</p>\n<p>If the application’s virtual memory region balloons, it can eventually lead to serious problems such as the RDP session blacking out and disconnecting, or delays in system operations and desktop GUI rendering.</p>\n<p>Incidentally, after starting <code class=\"language-text\">D4C.exe</code>, you can use Process Explorer from Sysinternals to watch the process’s virtual memory keep growing.</p>\n<p>You can also use Task Manager to confirm that the amount of virtual memory allocated across the whole system is increasing.</p>\n<p>The following screenshot shows Process Explorer and Task Manager launched while a user-mode memory leak issue was actually being reproduced.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/5c859791feb135bdd9bcccddc489040f/0b533/mem-leak-002.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 64.99999999999999%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACiUlEQVQ4y4VTy24TQRDcr+TMryAhceFKOIA4wIUDUpQQBREDISKOBZZjO4Y4ceIYE3ufzs7s7sw+Z130jJPwOjCrUvc+premusv64YdgEUPAQvCIY7FYgDGGJIkJEUTMIYRAXuQoCGVZGOQ53Zclqqqi58UtrIvzKdxpAO4kcGcezsZ9TIZtXPb3MT7+hsloivk8wdyOcDFxKDKEYUI/DRHHCdI0pR8nlMcGVuPjHtaevcD6dgO7zQM49gy+58Cdz2kTMZQFbZAGWaaZaUYVlFKGnUZJTDWiKIL1+qCFB+sbWPvUxJv+AIlIwTkDC68gRYLA94wUUgos6Votypa/ga66rlcFm1/G+PruFE4nxGzE4CUK312OQChkJUgGB0VaAQqoCmWgivoav+5lnMJ3A1ib7QHub+/hUe8MW8dTeG6G1sjH/pjBZlSlrKlgaVBmdDwqbuJfucprxKSttXE4xL2tXTzujNCYzKDqFIyOrEibulKIrxJInt5CMLkC/zPqd2HAYLUPR+juHuHqnPSibpd5RI2Zww8oJ/F5EN0WK8SKSZUpg5tcM1UZMWTU5eftDu5sbuJuq4WnxwNAhvCpEUJKKl7SMWgeeWI0EpGkoxdQJENF3c5ljlrnpGNdLek7AWu708PDnQaedHvYOT1BQcPsuK6ZLT2oNrH1PA8BDXxArMOQDMA5dZQbA5ieL1fdl0TC2u8N8PL9e3wYnqB/OUNOfWCMm4HVs2bbtjm+bTu0ITUbjUuunfFPweZhF6923mLvqI/B5EK/xc1S9dLMZEw21M7439IkrO7nHqaNA1TdMRbDMS7JKZ4zR0gsbT+mKJDEGfm5oKLacoLyjFyTmgJZlpmoWWsJfgIfANIgq66FSwAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/5c859791feb135bdd9bcccddc489040f/8ac56/mem-leak-002.webp 240w,\n/static/5c859791feb135bdd9bcccddc489040f/d3be9/mem-leak-002.webp 480w,\n/static/5c859791feb135bdd9bcccddc489040f/b0a15/mem-leak-002.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/5c859791feb135bdd9bcccddc489040f/8ff5a/mem-leak-002.png 240w,\n/static/5c859791feb135bdd9bcccddc489040f/e85cb/mem-leak-002.png 480w,\n/static/5c859791feb135bdd9bcccddc489040f/0b533/mem-leak-002.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/5c859791feb135bdd9bcccddc489040f/0b533/mem-leak-002.png\"\n            alt=\"Memory resources during a user-mode memory leak\"\n            title=\"Memory resources during a user-mode memory leak\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>In Process Explorer, you can see the size in the <code class=\"language-text\">[Private Bytes]</code> column for the <code class=\"language-text\">D4C.exe</code> row steadily increasing over time.</p>\n<p>On the <code class=\"language-text\">[Performance]</code> tab in Task Manager, you can also confirm that the amount of committed virtual memory is increasing.</p>\n<p>You can investigate a process’s memory consumption with many tools besides Process Explorer and Task Manager, such as Resource Monitor, VMMap, and Process Hacker.</p>\n<p>So when you suspect a memory leak, it is a good idea to use whichever tool fits your environment and preferences.</p>\n<h2 id=\"obtaining-a-process-dump\" style=\"position:relative;\"><a href=\"#obtaining-a-process-dump\" aria-label=\"obtaining a process dump permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Obtaining a process dump</h2>\n<p>Now that we have reproduced the application’s memory leak issue with <code class=\"language-text\">D4C.exe</code>, the next step is to obtain a process dump for analysis.</p>\n<p>For problems such as memory leaks that do not involve an application crash, an application crash dump is not generated automatically as in Chapter 4.</p>\n<p>Therefore, you need to use a tool of your choice to capture a process dump file while the problem is occurring.</p>\n<p>There are many tools that can capture process dump files, but in this book we will use Process Explorer and Procdump, both included in Sysinternals.</p>\n<p>First, let’s obtain a dump file with Process Explorer.</p>\n<p>Just as when we checked the process’s memory usage earlier, launch Process Explorer with administrator privileges.</p>\n<p>Next, right-click the <code class=\"language-text\">D4C.exe</code> row in the process list and click <code class=\"language-text\">[Create Dump] > [Create Full Dump...]</code>.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/6af4e90dbf17abd55228873bcbbee4f8/0b533/mem-leak-003.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 78.33333333333333%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAD/UlEQVQ4yy2U2W8bVRjF56+CV8TygATPVCDgAZBoHygSQiAeKgRCFBUhUaV0SdMtCU0cx/USu/FWOe44dmI7tuMkbprEjT3jbWbsiXcnsf3jJuVKR7rS1T3f951z9EmmYaAoRWrVGmbdRKvVKKkKmm6gaRqVcpnyGUpl6nUDXdcxtBqG+FetVDBNk3qjId4aGPU60v6hwstilapmkNnZpGQc8ULRaFRUjswmiloW5A1BWqNhtuifDAVGdAdDuv0Tup0OneYRnVaTwfEJUqmkcnbGJz3MRkFcTjkdDhl3THrdJkX1kKa+i6ZsUj5M0zgQRVN+aikHR2qGZjlPczdBcz/NuN9EerapcGutxfVom2uRHr+vmPwRNnmcaTGzrmDZUPh3Nc18OMaCvMacL879hQBX73n4zbHD37LBT84C39ny/OzXkNzLMtd+uc2fV+8zObGI9ZEPy0Mvuhi9XNUoKmU6gxFiynOIKwdqjWlvnHmbzM2/ppmZWmLuwTIzky6kO8FF3rx5g7fv3eE9+wLvP3XygYDRfa1NsVCgIcRmPGIscHbqehUlFmTieYA3/rnOu1O3eOfBJG/dnkAKxBNYwjLezS0yRp20cDet6UL4U+FcXbhbOndyPIbR6DVhTbibW5PZPtjHsZ4QUkRYjMbwbKSQ5FAY2727+G1Wwk47EbeL5LMALfUVR4aIiCjSarcF4ficbDAYoIqud+NRNuUQ1qm7LFvmCT6xCiwiOTwyjpsPcN6dRba4iFrdJJeC9MwGLTHyWZdnHfb7/XOyZquFWiyQWAnwQo7hf2TFNfUY9/05gjOCcDJUwu0p4VwusRIdEE2MiSWhf4wIsUZVBH00GjMU4w6H/2soQp2WfexkDZ766jiWCjjdRdzeCtKsP4l/NkTIFmdrpch2WCUnq4wGfdqmhlEtw+ngLKkCw3PCVl0XhAH2NvYJOlJ4FqK4LasEFsJIc6kMnwd8XJLDXMxm+DKb5uJWhm+9PS4vww8B+N4PXy/BVy742DrmYfJYFNMp5vMc7r7gILeDXiziTK0jra6u4Zm34Lc7SEcivMpmUXd22K30iefbxA+OiO2ZhHMG8l6TnDbClTvhM9uIb+w9flg64Uf3gEsOuGGJI02HcswuJZh+muDJyh7BlEYoW0dvdum1TLqmwXGvKSQQTh93zkfWhfO+QITH8gFXnmzzq32bKwITS0mkiUiSD21OPnJ7ubAc5IuVKJdze+w2WmLzaBQKKpWqzuvQQLs7EIuixN5zH7O5LBf8AT71ePjE7eFCIIi0Hs+zYU+SdCXZ8ubQknUaKbFdCm0KiopSKorc7VMtF9Brglw5pJTf52U6Rin9iowrQ9qTJeFMErOn+A/I0FB+UsG8mgAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/6af4e90dbf17abd55228873bcbbee4f8/8ac56/mem-leak-003.webp 240w,\n/static/6af4e90dbf17abd55228873bcbbee4f8/d3be9/mem-leak-003.webp 480w,\n/static/6af4e90dbf17abd55228873bcbbee4f8/b0a15/mem-leak-003.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/6af4e90dbf17abd55228873bcbbee4f8/8ff5a/mem-leak-003.png 240w,\n/static/6af4e90dbf17abd55228873bcbbee4f8/e85cb/mem-leak-003.png 480w,\n/static/6af4e90dbf17abd55228873bcbbee4f8/0b533/mem-leak-003.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/6af4e90dbf17abd55228873bcbbee4f8/0b533/mem-leak-003.png\"\n            alt=\"Capturing a process dump with Process Explorer\"\n            title=\"Capturing a process dump with Process Explorer\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>A File Explorer window will open, so save the dump file to any folder you like.</p>\n<p>If the full process dump is captured successfully, a dump file will be created in the specified folder with nearly the same size as the process memory size you saw in Process Explorer’s <code class=\"language-text\">[Private Bytes]</code> column.</p>\n<p>When you capture a dump with Process Explorer, the <code class=\"language-text\">D4C.exe</code> application is not terminated, so press <code class=\"language-text\">[Ctrl+C]</code> to stop the application manually.</p>\n<p>Now we have obtained a process dump for analysis, but you can also capture an equivalent dump file with Procdump.</p>\n<p>Using Procdump is very simple.</p>\n<p>To capture a process dump of <code class=\"language-text\">D4C.exe</code>, run the following command in an elevated Command Prompt.</p>\n<div class=\"gatsby-highlight\" data-language=\"powershell\"><pre class=\"language-powershell\"><code class=\"language-powershell\">procdump<span class=\"token punctuation\">.</span>exe <span class=\"token operator\">-</span>ma <span class=\"token operator\">-</span>w D4C<span class=\"token punctuation\">.</span>exe</code></pre></div>\n<p>When you run the command above, a process dump is created in the current folder.</p>\n<p>The <code class=\"language-text\">-ma</code> option specifies that the dump type to capture is a full dump.</p>\n<p>The <code class=\"language-text\">-w</code> option specifies the name of the process for which the dump file should be captured.</p>\n<p>Although we will not use it in this book, when you capture an application process dump with Procdump, you can define dump collection conditions in detail, such as an application hang or thresholds for CPU usage and memory size.</p>\n<p>So if the timing or reproduction conditions of the problem are unclear, you can use Procdump to capture a process dump under whatever conditions you need and smoothly obtain the dump file required for the investigation.</p>\n<p>For a list of Procdump options, refer to the published documentation.</p>\n<br>\n<p>ProcDump:</p>\n<p><a href=\"https://learn.microsoft.com/ja-jp/sysinternals/downloads/procdump\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/sysinternals/downloads/procdump</a></p>\n<br>\n<h2 id=\"examining-the-exception-code-in-the-process-dump\" style=\"position:relative;\"><a href=\"#examining-the-exception-code-in-the-process-dump\" aria-label=\"examining the exception code in the process dump permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Examining the exception code in the process dump</h2>\n<p>Now that we have the process dump for analysis, let’s start investigating the memory leak issue.</p>\n<p>As in Chapter 4, we will begin by loading the process dump in WinDbg and examining the exception code.</p>\n<p>It does not matter whether you use the dump file captured with Process Explorer or the one captured with Procdump.</p>\n<p>As shown below, the exception information you can obtain from either kind of process dump with the <code class=\"language-text\">.exr -1</code> command is the same.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Exception code from a process dump captured with Process Explorer\n0:000> .exr -1\nExceptionAddress: 0000000000000000\n   ExceptionCode: 80000003 (Break instruction exception)\n  ExceptionFlags: 00000000\nNumberParameters: 0\n\n# Exception code from a process dump captured with Procdump\n0:000> .exr -1\nExceptionAddress: 0000000000000000\n   ExceptionCode: 80000003 (Break instruction exception)\n  ExceptionFlags: 00000000\nNumberParameters: 0</code></pre></div>\n<p>From this, we can see that the exception code recorded in the captured process dump is <code class=\"language-text\">0x80000003</code>.</p>\n<p>If you refer to the official documentation<sup id=\"fnref-2\"><a href=\"#fn-2\" class=\"footnote-ref\">2</a></sup>, you can see that this exception code relates to breakpoint detection.</p>\n<p>Also, as the output of the <code class=\"language-text\">.exr -1</code> command itself says, <code class=\"language-text\">Break instruction exception</code>, we can tell that this exception is related to a breakpoint.</p>\n<p>Of course, <code class=\"language-text\">D4C.exe</code> does not have a hardcoded breakpoint.</p>\n<p>In other words, we can conclude that this exception was forcibly raised by Process Explorer or Procdump in order to generate the dump file.</p>\n<p>In this way, when you generate a dump file to investigate a problem that does not involve a crash, the tool intentionally raises an exception.</p>\n<p>Therefore, when you analyze a dump file for a non-crash problem such as the memory leak issue in this chapter, you need to keep in mind that the exception information you can obtain with <code class=\"language-text\">.exr -1</code> and <code class=\"language-text\">!analyze -v</code> is not useful.</p>\n<h2 id=\"preparation-before-investigating-the-memory-leak-in-the-dump-file\" style=\"position:relative;\"><a href=\"#preparation-before-investigating-the-memory-leak-in-the-dump-file\" aria-label=\"preparation before investigating the memory leak in the dump file permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Preparation before investigating the memory leak in the dump file</h2>\n<p>So if the exception information in the dump file is not useful, how should we proceed with the analysis?</p>\n<p>In general, before analyzing a dump file, it is important to narrow down the likely source of the problem to some extent.</p>\n<p>For example, in this case we assume that, before analyzing the dump file, we have already identified with Process Explorer, Task Manager, or Resource Monitor that <code class=\"language-text\">D4C.exe</code> is experiencing a memory leak.</p>\n<p>Also, before analyzing the dump file, it is helpful to identify exactly which region of the memory allocated to the <code class=\"language-text\">D4C.exe</code> process is ballooning.</p>\n<p>For each section allocated in a user-mode process’s virtual address space, Sysinternals VMMap lets you confirm that they are classified as follows.<sup id=\"fnref-3\"><a href=\"#fn-3\" class=\"footnote-ref\">3</a></sup></p>\n<ul>\n<li>Image</li>\n<li>Mapped File</li>\n<li>Shareable</li>\n<li>Heap</li>\n<li>Managed Heap</li>\n<li>Stack</li>\n<li>Private Data</li>\n</ul>\n<p>The Image region is allocated to map executable images and similar content.</p>\n<p>The Mapped File region is allocated for data files mapped into memory.</p>\n<p>The Shareable region contains sharable memory that is not mapped into the Image or Mapped File regions.</p>\n<p>The Heap region is the memory area used for heaps owned by the process. (Managed Heap is allocated by the CLR, so nothing is shown for processes that do not use .NET.)</p>\n<p>In general, when a user-mode application suffers a memory leak, the size of this Heap region increases.</p>\n<p>The Stack region is the area for the stack owned by each executing thread in the process, and the Private Data region is used for memory allocations other than stacks and heaps.</p>\n<p>The following is the result of inspecting the <code class=\"language-text\">D4C.exe</code> process with VMMap before the application’s memory leak occurs.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/4bef7df84701abff370d018678582621/0b533/mem-leak-004.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 76.25%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAC8ElEQVQ4y5WSaW8bVRSG568CHyIkJNQC4k+AkIoQpUUhrWTauqkbB1rHdhwnXuIlduzJuN5m7PEyi+3xMt5IZEV5uJmGb1CVKz16z3vP0V2P1GhozJdzrq6uWK/XHqvViuVyyWKx8Pz19TX/Nm5ubjw2m43nNU1D6vQMdL1DS2t5qgk1DAPbtrEsi8lkguu6H2Q6m3kby7KMFK+Y1NU23U4HVVVptdpe0UwUzdzZe51N/5Op4HbTy8tLFEVB6ne73iK3k9Nbpu8L/g+O43i3yuVySEqoTOblgErIoRadU4241D6WqEs9PCN7viAl10kchZGqxwWqpRJ6q8/AcrDNEQNTaP8j6Y3EW48x7QHpVBKpFM5QzhXRVROjY9NvC3QD0+pj2ZbA/AB3ecsUz6aRTIoFm8cd5D9n4gozmrEFjeia5omBZXYZO2NGwyGT8VjEDs5o5PFPfJvz9C7OZDJIDfEhQ/GTY9Fz4/mcieg/WyzUaOk47gJjMOLsXKbdM5ku18I7XLyrM5rOGU5cSkoVrdNjebnhJCFOeBY7YNVtsO41GdZKqNljcqE90m+DuO13IlenmU3QVwr81W8yb1dpFU+ZqBXPd84z6OU8G7vNSSyKdPLgAfpTH8bvL+g9f4bt91P/7THpn37AfunHebVL+dcfqT3ZZhwIYPlfCP8zXVE7Eb6684iL7Ue4wSBHwT2kx74dHvqesh8/4jCXIl7MEhWn3D14xWE+xfF5ntfRIMGjN14cO0sTOo3f5XK8SUR4ffgHSblIKCLaJry3RXT/U9rK17Qu7gu+4jTyJeHAJ2jyPYzGN+TjW2RiW17cqdwnF/+CWvEepvDl1OckDj5joH3LYcSHlNj/jkb6IeO6H0t5hqsFaBeekHr7PY6Ym7cCdIo7NPPbTJu7Xp1e8mFVnjNTd71cJfULK32PbFKc0NDFL/e6LMcjTL2FWlGolUuUclkaFzJNRfa0pzZxjD6jfterHwod9XseQ8FE9GKxUOBv9OoibKxANlEAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/4bef7df84701abff370d018678582621/8ac56/mem-leak-004.webp 240w,\n/static/4bef7df84701abff370d018678582621/d3be9/mem-leak-004.webp 480w,\n/static/4bef7df84701abff370d018678582621/b0a15/mem-leak-004.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/4bef7df84701abff370d018678582621/8ff5a/mem-leak-004.png 240w,\n/static/4bef7df84701abff370d018678582621/e85cb/mem-leak-004.png 480w,\n/static/4bef7df84701abff370d018678582621/0b533/mem-leak-004.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/4bef7df84701abff370d018678582621/0b533/mem-leak-004.png\"\n            alt=\"Inspecting the process right after launch with VMMap\"\n            title=\"Inspecting the process right after launch with VMMap\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>After selecting menu item <code class=\"language-text\">2</code> and reproducing the application’s memory leak issue, refresh the VMMap display and you can confirm that the Heap region (the orange region) has grown significantly within the process’s memory space, as shown below.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/d473103086c66aec914de1aa5dd51b39/0b533/mem-leak-005.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 79.16666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAQCAYAAAAWGF8bAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADIklEQVQ4y5WUW08bVxSF5y9H6ktSVUKtmlISpahpmpshIEGwYwwkBWKbEIzxbYxvmEvAxmPP2AbMXD02xvTl62FCUR8aNX34tPZa++wzczSjIxXKu1i2iev2cBzHo9t1sG37lv7FBVdXVwyHw1v+6fv9PpeXlwwGA6SzkzbtdhtNa3rabH7WTqfjqW073sDXIkUKDY6OKlQrFQ4PPnF0eIRpGFgC09CxTOMzxr9wk9umiWNb3mmk49Y5SusUszdAd1wMt4/dv8QS/qvoDzgXc82Owem5jqSGZ1Hf+bA2gzjxEPbmvFdf63/hrYvP01mfo77wDCW+cb3hDLX5J5ysTuHEAtgb/v/F9Yy+Nksj9IT61gexYeQ19aUXGBsB8YbXTw5+mS/09Y9+1MVnaOk1pOYfPupzD9FXXmCHJzBXxfHf+3Aik0InRDaJuzZ1433emm50Clv0rn13bRpz+Sm1hZcotQZS+7CMo1Zu6bVqdLUq7YOi588rexznUpx82sHVjtGr+9SLMlb9ELt+JOoMrb0C/RONlvjlpEx+G2fg4ly4dCydqqqQKxVIyBlskbU6J2QLBWqaSm94IVQhX94RX9bE6Jrkd0scHFdxhz0UpYqUe/473aUQzmKQU/8M2vQrUuOPSIw/pCuys2CAou8pyswU7tI86txryhPPOQvMYi0E2Z30sffqJf2FN9STW0izU9OE5kKsRzZIbSXIy9sk4+uEV+bJJFLIqQzh5RAfIstkU7LIksQ+RsXauOdj61Eiq4vIyTRFcRLJP3uXN/67ZDPjbAvy2V+JhscIBr4lJ49TKjwmvDoi+J6dwm8ie8T78E+kE78I/5h4bJR3b0co5oQvRZA2V+5QTtxDV37mrHofq/GA/fQIyegdzPoo3eYDaqXv2JfvYatjoj/KcekHWof3RW8MbW+EXOwbHO1H1KrYUI6uoBYSGJUyWkmmXZapZjdJhd+KPE1TZEouQS2fpHNQ8NB2srR2c17dFqoU05zt5zht1JB6FwP6gyGDqz/RTQtF1ajfoPxNQ+W0c44trjir6woVCPVqgdPrYYhbSTdM/gJVY1U9Zy7DuQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/d473103086c66aec914de1aa5dd51b39/8ac56/mem-leak-005.webp 240w,\n/static/d473103086c66aec914de1aa5dd51b39/d3be9/mem-leak-005.webp 480w,\n/static/d473103086c66aec914de1aa5dd51b39/b0a15/mem-leak-005.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/d473103086c66aec914de1aa5dd51b39/8ff5a/mem-leak-005.png 240w,\n/static/d473103086c66aec914de1aa5dd51b39/e85cb/mem-leak-005.png 480w,\n/static/d473103086c66aec914de1aa5dd51b39/0b533/mem-leak-005.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/d473103086c66aec914de1aa5dd51b39/0b533/mem-leak-005.png\"\n            alt=\"Inspecting the process after the memory leak occurs with VMMap\"\n            title=\"Inspecting the process after the memory leak occurs with VMMap\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>If you need to check the process’s memory usage from the dump file in WinDbg, you can use the <code class=\"language-text\">!address</code> extension.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/ce670f270a89aa946ed74ae531b1658b/0b533/mem-leak-007.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 66.66666666666666%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACMElEQVQ4y1VU2XLaQBDU//9LEr/lLYkhFJc4dJCyIYBVBgE60IUkzNWeXiwKtmpqvetRT09PL1qSJHAcB1mWwXVd5HmO1WqFOI4RBAE8z8PlclH3h8MBRVFgt9vheDyiLEucz2dwMYdL46VlWQrAtm1EUYTBYIDpdIrhcIh+v68Sqw+Zv1wuFQF+Q+AHQFY2TVP90zAMkDH3VquFRqOBbreL+0XA9Xqt8n3fv90/ABLgHpAF2u02ms2mAtzv9wro4+NDtUxJCDabzR5aZtwAK2YVIP8mWK/Xw3a7VcGi1I9g1HcymdyYVUtjArWidtz5ETWkdp1OB7quI01TVYi6MZ+DIiAZkj2HRS1PpxO0OL4yC4UBQarWWd2UYRmG+cCALVNDFiFTntklg5JoaXptMRLAoTC7ng04b28YjUbigCvgpZqyAITCjoDckyRWdwcBUy1vhaFp2fDDLQbChueh7NPZXN0bpqUSD6czziJXXuzhvC9QlHtkeaHula2+Qqu/Bnj6a+PPvw2+10zUXnz8qFn42RnjqW7h27MBfbFH28nRfS/R+B/jl+2i/urjt7XAs71EbSTx4kGf+tAiYTSQYfhBCL3XR/TF0JZ2edZlylxHYcJ5ZqKVuxIfJinWmw0WS1eM7oqeAYIwhJZlqdLspqFMky/HkCK0De/ujVuW9KGrXMGnyldDX3reRgYaCaDYgFOlz2iXyoe0UFtsUz29CpDT5HQZ8/kc4/FYBX8POP1P/bjF8/bNr3cAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/ce670f270a89aa946ed74ae531b1658b/8ac56/mem-leak-007.webp 240w,\n/static/ce670f270a89aa946ed74ae531b1658b/d3be9/mem-leak-007.webp 480w,\n/static/ce670f270a89aa946ed74ae531b1658b/b0a15/mem-leak-007.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/ce670f270a89aa946ed74ae531b1658b/8ff5a/mem-leak-007.png 240w,\n/static/ce670f270a89aa946ed74ae531b1658b/e85cb/mem-leak-007.png 480w,\n/static/ce670f270a89aa946ed74ae531b1658b/0b533/mem-leak-007.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/ce670f270a89aa946ed74ae531b1658b/0b533/mem-leak-007.png\"\n            alt=\"Output of the !address command\"\n            title=\"Output of the !address command\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>As shown above, the output of the <code class=\"language-text\">!address</code> command also tells us that a very large number of Heap regions have been allocated in the process.</p>\n<p>Incidentally, the output of <code class=\"language-text\">!address</code> is very large, so it is often easier to investigate with the <code class=\"language-text\">!address -summary</code> command, which can collect statistical information.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/d5430d2cbb67e423b10232465adedab3/0b533/mem-leak-008.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 87.5%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACFUlEQVQ4y52Uh24CMRBE/f8fRRUCIUCAQPTee+9lozeRo1QpyUrOYZ/9PDu7F7fdbm25XNpms7HFYmHMH4+HEc/nU+Mv4SqVitVqNavX69bpdAQ9nU4fgH8Bu1QqZZlMRgPoer222+32LfA3wwEqFAqWz+cFbTQaNh6PNf4TbjAY2GQy0VitVvKT37PZTGoPh4Pt93vzXnu/mbO+2+00Zz+ZCXi9Xu1+v3+5jU2j0Ujvut2uRaNR+Y3PZNRqtazX69l0OrVSqSSw44+PzwW4XC5SSQAMBALWbDZtPp9bPB63drutgWrgAtIiAHj64eekANSrzWazNhwOBaA7AJMBl/b7fdnj0um06Ezwg5dAzuezVHEAMMBisag1gLQYcBTyjieeulwup4Xj8SgvgfEECJxCeWC5XJYS1gDQCdQApXgphYlEQlUFwkEKwOA3GwHR6Cjz2VAUUgbGb/ZVq9VXhVQH6RxCFUq5CSAKOICfqKLxWcMaYFzGWTLBGhiOVgiFQvKEdN8D2YwygKQUi8UEBYRVqPUfAgpV5XA4rP5ikZuQ/z5Ig8C7SCSiJwdJH5UoY/7WNiz6VqD7SRGlKASGvxSAi9jDfg4DZo5a9nn/BSQl/7X44tCL3nwyAMoaKXuLuCSZTAruPwyHwT8FN9MqHkjgWTAY1BeDv3wxiCIQ5n76V0Wgls10AqkRWECDow6LKAYd4BkvpTVS3FyJA2gAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/d5430d2cbb67e423b10232465adedab3/8ac56/mem-leak-008.webp 240w,\n/static/d5430d2cbb67e423b10232465adedab3/d3be9/mem-leak-008.webp 480w,\n/static/d5430d2cbb67e423b10232465adedab3/b0a15/mem-leak-008.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/d5430d2cbb67e423b10232465adedab3/8ff5a/mem-leak-008.png 240w,\n/static/d5430d2cbb67e423b10232465adedab3/e85cb/mem-leak-008.png 480w,\n/static/d5430d2cbb67e423b10232465adedab3/0b533/mem-leak-008.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/d5430d2cbb67e423b10232465adedab3/0b533/mem-leak-008.png\"\n            alt=\"Output of the !address -summary command\"\n            title=\"Output of the !address -summary command\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>In this way, by running <code class=\"language-text\">!address -summary</code> in WinDbg after loading the process dump, we can also confirm that the Heap region allocated inside the process has ballooned.</p>\n<p>At this point, we have identified that the <code class=\"language-text\">D4C.exe</code> memory leak issue is likely being caused by the growth of the Heap region.</p>\n<h2 id=\"investigating-the-heap-region-in-the-process-dump\" style=\"position:relative;\"><a href=\"#investigating-the-heap-region-in-the-process-dump\" aria-label=\"investigating the heap region in the process dump permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Investigating the Heap region in the process dump</h2>\n<p>In the previous section, we confirmed that the cause of the <code class=\"language-text\">D4C.exe</code> memory leak issue is the ballooning of the Heap region inside the user-mode process.</p>\n<p>Applications running on Windows are managed by a component called the heap manager, and generally create heaps and allocate memory by using Windows API functions such as <code class=\"language-text\">HeapCreate</code><sup id=\"fnref-4\"><a href=\"#fn-4\" class=\"footnote-ref\">4</a></sup> and <code class=\"language-text\">HeapAlloc</code><sup id=\"fnref-5\"><a href=\"#fn-5\" class=\"footnote-ref\">5</a></sup>.<sup id=\"fnref-6\"><a href=\"#fn-6\" class=\"footnote-ref\">6</a></sup></p>\n<p>When analyzing the Heap region of an application’s process dump in WinDbg, you can use the <code class=\"language-text\">!heap</code> extension.<sup id=\"fnref-7\"><a href=\"#fn-7\" class=\"footnote-ref\">7</a></sup></p>\n<p>After loading the process dump captured during the memory leak issue into WinDbg and running the <code class=\"language-text\">!heap</code> command, we can confirm that three NT Heaps exist in the process, as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">0:000> !heap\n        Heap Address      NT/Segment Heap\n         1f1adb90000              NT Heap\n         1f1ada70000              NT Heap\n         1f1adf50000              NT Heap</code></pre></div>\n<p>NT Heap is the default heap used by Windows applications.</p>\n<p>In addition to NT Heap, heaps used by Windows applications include the segment heap added in Windows 10 / Windows Server 2016<sup id=\"fnref-8\"><a href=\"#fn-8\" class=\"footnote-ref\">8</a></sup>, but this book does not use the segment heap, so from here on all heaps refer to NT Heaps.</p>\n<p>Now that the <code class=\"language-text\">!heap</code> command has shown us that three heaps exist in the process, next we will use the <code class=\"language-text\">-S</code> option to display summary information for each heap.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/d6de6d5e929e139c399f1533cc38ac87/0b533/app-heap-001.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 28.750000000000004%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA5klEQVQY01VRyQqFQAyb//83N1QUVNz3fcODSx8pjPgOoSnTJg0jhmGgqqpoHEe6ruvFeZ5//X3f9DzPH77vEgJiQJ7nlGXZW4uioDRNKY5j7h3HIUVRSNM0hmEYlCQJv0dRxBwQlmWxCEQhACFwVVV5yfd9CoKAyrKktm2p6zpCqqZpaJ5nWteV67IszMW+71TXNQODcMEirgCHCXosQQwXwRTLMg1mUGEqEMU0TYZt26TrOotjCAMQRQ3DkEVlCnAYfa/myIjjeR4D8VzX5fPl0DRNfA364ziYI9W2bW8F8Kl939MP/R6/BIZRp1cAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/d6de6d5e929e139c399f1533cc38ac87/8ac56/app-heap-001.webp 240w,\n/static/d6de6d5e929e139c399f1533cc38ac87/d3be9/app-heap-001.webp 480w,\n/static/d6de6d5e929e139c399f1533cc38ac87/b0a15/app-heap-001.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/d6de6d5e929e139c399f1533cc38ac87/8ff5a/app-heap-001.png 240w,\n/static/d6de6d5e929e139c399f1533cc38ac87/e85cb/app-heap-001.png 480w,\n/static/d6de6d5e929e139c399f1533cc38ac87/0b533/app-heap-001.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/d6de6d5e929e139c399f1533cc38ac87/0b533/app-heap-001.png\"\n            alt=\"Displaying heap summary information with the !heap -S command\"\n            title=\"Displaying heap summary information with the !heap -S command\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Looking at the output of the <code class=\"language-text\">!heap -S</code> command, we can see that among the three heaps, the heap at <code class=\"language-text\">0x1f1adb90000</code> is extremely large and is the one that has ballooned.</p>\n<p>To gather information from a different angle, let’s also run the <code class=\"language-text\">!heap -a</code> command.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/3a96e857210015c6994a2a0b58df3a4e/0b533/app-heap-002.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 27.500000000000004%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAGCAYAAADDl76dAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA/UlEQVQY03WQzYqDQBCEff93UiEao4nGPxRB0ahoUIMiesuhluplYC870FbLdH9d01rbtqiqCr7v4/P5YNs28Hy/X8zzjHVdcZ4n9n3HcRxSw///jtb3PfI8RxRFCIIAWZYJqK5riWmaZCAHN02DsiwxjiPe77fosiwyhMFcI+R+v2MYBsRxDNM0BWwYBh6PB7qug67rUuN5HhzHQZqmopfLRYwkSSK9z+fzF3i9XsUNL23bFrUsS8Cv10samd9uN7iui6IoZABzglivXqjRBSFsVEBOosO/QAK4ZypXRBOsJTAMQwkB8kP7CkhnfAKVAO5OAdV6FJBBoHLJ+x9PpKUPK3X8mQAAAABJRU5ErkJggg=='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/3a96e857210015c6994a2a0b58df3a4e/8ac56/app-heap-002.webp 240w,\n/static/3a96e857210015c6994a2a0b58df3a4e/d3be9/app-heap-002.webp 480w,\n/static/3a96e857210015c6994a2a0b58df3a4e/b0a15/app-heap-002.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/3a96e857210015c6994a2a0b58df3a4e/8ff5a/app-heap-002.png 240w,\n/static/3a96e857210015c6994a2a0b58df3a4e/e85cb/app-heap-002.png 480w,\n/static/3a96e857210015c6994a2a0b58df3a4e/0b533/app-heap-002.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/3a96e857210015c6994a2a0b58df3a4e/0b533/app-heap-002.png\"\n            alt=\"Displaying heap segment information with the !heap -a command\"\n            title=\"Displaying heap segment information with the !heap -a command\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>Running <code class=\"language-text\">!heap -a</code> confirms that the heap at <code class=\"language-text\">0x1f1adb90000</code> we identified with <code class=\"language-text\">!heap -S</code> contains 84 segments. (Each line beginning with <code class=\"language-text\">Segment at</code> corresponds to one segment.)</p>\n<p>On Windows systems, NT Heap is managed by the <code class=\"language-text\">ntdll!_HEAP</code> structure.<sup id=\"fnref-9\"><a href=\"#fn-9\" class=\"footnote-ref\">9</a></sup></p>\n<p>Let’s run <code class=\"language-text\">dt ntdll!_HEAP</code> in WinDbg after loading the process dump and inspect the structure information for <code class=\"language-text\">ntdll!_HEAP</code>.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">0:000> dt ntdll!_HEAP\n  +0x000 Segment          : _HEAP_SEGMENT\n  +0x000 Entry            : _HEAP_ENTRY\n  +0x010 SegmentSignature : Uint4B\n  +0x014 SegmentFlags     : Uint4B\n  +0x018 SegmentListEntry : _LIST_ENTRY\n  +0x028 Heap             : Ptr64 _HEAP\n  +0x030 BaseAddress      : Ptr64 Void\n  +0x038 NumberOfPages    : Uint4B\n  +0x040 FirstEntry       : Ptr64 _HEAP_ENTRY\n  +0x048 LastValidEntry   : Ptr64 _HEAP_ENTRY\n{{ omitted }}</code></pre></div>\n<p>As shown above, the <code class=\"language-text\">ntdll!_HEAP</code> structure starts with the <code class=\"language-text\">ntdll!_HEAP_SEGMENT</code> and <code class=\"language-text\">ntdll!_HEAP_ENTRY</code> structures.</p>\n<p>Next, let’s inspect the information for the <code class=\"language-text\">ntdll!_HEAP_SEGMENT</code> and <code class=\"language-text\">ntdll!_HEAP_ENTRY</code> structures.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Dump structure information for ntdll!_HEAP_SEGMENT\n0:000> dt ntdll!_HEAP_SEGMENT\n +0x000 Entry            : _HEAP_ENTRY\n +0x010 SegmentSignature : Uint4B\n +0x014 SegmentFlags     : Uint4B\n +0x018 SegmentListEntry : _LIST_ENTRY\n +0x028 Heap             : Ptr64 _HEAP\n +0x030 BaseAddress      : Ptr64 Void\n +0x038 NumberOfPages    : Uint4B\n +0x040 FirstEntry       : Ptr64 _HEAP_ENTRY\n +0x048 LastValidEntry   : Ptr64 _HEAP_ENTRY\n +0x050 NumberOfUnCommittedPages : Uint4B\n +0x054 NumberOfUnCommittedRanges : Uint4B\n +0x058 SegmentAllocatorBackTraceIndex : Uint2B\n +0x05a Reserved         : Uint2B\n +0x060 UCRSegmentList   : _LIST_ENTRY\n\n# Dump structure information for ntdll!_HEAP_ENTRY\n0:000> dt ntdll!_HEAP_ENTRY \n +0x000 UnpackedEntry    : _HEAP_UNPACKED_ENTRY\n +0x000 PreviousBlockPrivateData : Ptr64 Void\n +0x008 Size             : Uint2B\n +0x00a Flags            : UChar\n +0x00b SmallTagIndex    : UChar\n +0x008 SubSegmentCode   : Uint4B\n +0x00c PreviousSize     : Uint2B\n +0x00e SegmentOffset    : UChar\n +0x00e LFHFlags         : UChar\n +0x00f UnusedBytes      : UChar\n +0x008 CompactHeader    : Uint8B\n +0x000 ExtendedEntry    : _HEAP_EXTENDED_ENTRY\n +0x000 Reserved         : Ptr64 Void\n +0x008 FunctionIndex    : Uint2B\n +0x00a ContextValue     : Uint2B\n +0x008 InterceptorValue : Uint4B\n +0x00c UnusedBytesLength : Uint2B\n +0x00e EntryOffset      : UChar\n +0x00f ExtendedBlockSignature : UChar\n +0x000 ReservedForAlignment : Ptr64 Void\n +0x008 Code1            : Uint4B\n +0x00c Code2            : Uint2B\n +0x00e Code3            : UChar\n +0x00f Code4            : UChar\n +0x00c Code234          : Uint4B\n +0x008 AgregateCode     : Uint8B</code></pre></div>\n<p>From the information above, we can see that the <code class=\"language-text\">ntdll!_HEAP</code> structure is composed of <code class=\"language-text\">ntdll!_HEAP_SEGMENT</code> structures that include <code class=\"language-text\">ntdll!_HEAP_ENTRY</code> structures.</p>\n<p>On Windows XP and earlier, you can traverse the <code class=\"language-text\">ntdll!_HEAP_ENTRY</code> structures inside a specific heap segment in a process by repeatedly advancing by the <code class=\"language-text\">Size</code> value of <code class=\"language-text\">ntdll!_HEAP_ENTRY</code> multiplied by 8.<sup id=\"fnref-10\"><a href=\"#fn-10\" class=\"footnote-ref\">10</a></sup></p>\n<p>However, this method cannot be used on Vista and later, because ASLR randomizes the process heap.<sup id=\"fnref-11\"><a href=\"#fn-11\" class=\"footnote-ref\">11</a></sup></p>\n<p>Therefore, to traverse the <code class=\"language-text\">ntdll!_HEAP_ENTRY</code> structures inside a heap segment, we will use the <code class=\"language-text\">!heap</code> extension.</p>\n<p>First, we specified <code class=\"language-text\">0x1f1adb90000</code>, the address of the heap that has ballooned this time, and retrieved the information inside that heap with the <code class=\"language-text\">!heap -a 0x1f1adb90000</code> command. (You can get equivalent output by using the heap ID and running <code class=\"language-text\">!heap -a 1</code>.)</p>\n<p>The output of this command is extremely long, so as needed, it is a good idea to enable output to a file with the <code class=\"language-text\">.logopen</code> command. (The <code class=\"language-text\">.logopen</code> command is described in this book’s “Appendix A: WinDbg Tips”.)</p>\n<p>When we actually ran <code class=\"language-text\">!heap -a 0x1f1adb90000</code> in WinDbg with the process dump loaded, we were able to enumerate the 84 heap segments in this heap and the heap entries within them.</p>\n<p>The following is an excerpt showing only the output for the 84th heap segment and the heap entries inside it.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\"># Excerpt showing only the output for the 84th heap segment and its heap entries\nSegment83 at fbec0000:\n  Flags:           00000000\n  Base:            1f1fbec0000\n  First Entry:     fbec0070\n  Last Entry:      1f1fce8f000\n  Total Pages:     00000fcf\n  Total UnCommit:  00000b5b\n  Largest UnCommit:00000000\n  UnCommitted Ranges: (1)\n\nHeap entries for Segment83 in Heap 000001f1adb90000\n  address: psize . size  flags   state (requested size)\n  000001f1fbec0000: 00000 . 00070 [101] - busy (6f)\n  000001f1fbec0070: 00070 . 41f90 [101] - busy (41f80) Internal \n  000001f1fbf02000: 41f90 . 42010 [101] - busy (41ff0) Internal \n  000001f1fbf44010: 42010 . 41ff0 [101] - busy (41fe0) Internal \n  000001f1fbf86000: 41ff0 . 42010 [101] - busy (41ff0) Internal \n  000001f1fbfc8010: 42010 . 41ff0 [101] - busy (41fe0) Internal \n  000001f1fc00a000: 41ff0 . 42010 [101] - busy (41ff0) Internal \n  000001f1fc04c010: 42010 . 00400 [101] - busy (3f0) Internal \n  000001f1fc04c410: 00400 . 41bf0 [101] - busy (41be0) Internal \n  000001f1fc08e000: 41bf0 . 42010 [101] - busy (41ff0) Internal \n  000001f1fc0d0010: 42010 . 41ff0 [101] - busy (41fe0) Internal \n  000001f1fc112000: 41ff0 . 42010 [101] - busy (41ff0) Internal \n  000001f1fc154010: 42010 . 41ff0 [101] - busy (41fe0) Internal \n  000001f1fc196000: 41ff0 . 42010 [101] - busy (41ff0) Internal \n  000001f1fc1d8010: 42010 . 41ff0 [101] - busy (41fe0) Internal \n  000001f1fc21a000: 41ff0 . 42010 [101] - busy (41ff0) Internal \n  000001f1fc25c010: 42010 . 41ff0 [101] - busy (41fe0) Internal \n  000001f1fc29e000: 41ff0 . 42010 [101] - busy (41ff0) Internal \n  000001f1fc2e0010: 42010 . 41ff0 [101] - busy (41fe0) Internal \n  000001f1fc322000: 41ff0 . 11fc0 [100]\n  000001f1fc333fc0: 11fc0 . 00040 [111] - busy (3d)\n  000001f1fc334000:      00b5b000      - uncommitted bytes.</code></pre></div>\n<p>When a program writes information into heap memory allocated by the process, the written data is recorded in the memory region after the header of each heap entry.<sup id=\"fnref-12\"><a href=\"#fn-12\" class=\"footnote-ref\">12</a></sup></p>\n<p>If we actually specify the addresses of several heap entries identified with <code class=\"language-text\">!heap -a 0x1f1adb90000</code> and dump around <code class=\"language-text\">0x100</code> bytes of memory, we can confirm that the string <code class=\"language-text\">==> Allocated addr: &lt;Address></code> is written in each heap entry as shown below.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/559c07717c204960e7c18d7858c7fc1d/0b533/app-heap-003.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 97.91666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACZElEQVQ4y22Uh3JqMQxE+f+vAgKB0HsNhFBT6DVAQJmjN0sub8KMx8LXXq20a4dKpZLV63VLpVLWaDQ8LpfL1m637f393YbDofX7fXt7e/MxGo18fTwe29fXl12vVzscDjabzez7+9tCuVzOKpWKRSIRGwwG1mq1HLhWq/ngWz6f97harXqyZrNpxWLRQfjtdjsfgIfYDKt4PG69Xs8Bn5+f/VCn0/GYBMz8Z11Jl8ulbTYbm06nNplMHNQZkjkajTog4AzWxJS2AMSAsWYYAtbtdj0h4M6Qw/SQXrEREEpTTylPSfiuPsMo+POS1cPHx0fvIYd0QH1TD9kHW2KSwAghjsejnc/nf6LwgQ3JZPLWbCkvhSmJZK+vrz6IaY9UBgilHVCiJBIJbzoxCQDnML1hAAD4y8uLA7K2Xq+dHaV/fHz82oZeoTIHUJAhcSSK/quHsg0M9/u9g91sAxt6+JdtMDgJmbWutfl8bp+fn7fKFovFL8NYLHZnG5UtMwOib8SswZCymWkPPb0xpGQWdUPkw79sIx9ut1u7XC6uMIP4jiFqspGD6hvghULhBggzYr7rugHG7IBkBzCdTvscLBHluFLYR4+DBo+DrAIgnjydThbKZrOeEYaUTDkqmwQyM7GuIsKRlJcHMMTgBbpTGR9iG/kOhnocSKhHgVjzarVyhjwSKO4+FMOHhwc3rZgFHwc9WWIv5jwMMJMbAA7RcDI+PT15ycHS2EgswKCdpHLwLrsomUzGN4XDYS+RfrEZsWQTPXEAax0i/9vGS+YAQJSOmroRsA72ULdG67DENoCgrgB/AASFoYQ4uqxvAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/559c07717c204960e7c18d7858c7fc1d/8ac56/app-heap-003.webp 240w,\n/static/559c07717c204960e7c18d7858c7fc1d/d3be9/app-heap-003.webp 480w,\n/static/559c07717c204960e7c18d7858c7fc1d/b0a15/app-heap-003.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/559c07717c204960e7c18d7858c7fc1d/8ff5a/app-heap-003.png 240w,\n/static/559c07717c204960e7c18d7858c7fc1d/e85cb/app-heap-003.png 480w,\n/static/559c07717c204960e7c18d7858c7fc1d/0b533/app-heap-003.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/559c07717c204960e7c18d7858c7fc1d/0b533/app-heap-003.png\"\n            alt=\"Dumping memory at heap entry addresses\"\n            title=\"Dumping memory at heap entry addresses\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<h2 id=\"identifying-the-code-responsible-for-the-memory-leak\" style=\"position:relative;\"><a href=\"#identifying-the-code-responsible-for-the-memory-leak\" aria-label=\"identifying the code responsible for the memory leak permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Identifying the code responsible for the memory leak</h2>\n<p>By analyzing the allocated heap regions from the dump file, we identified that the memory leak is very likely occurring because heap regions containing the string <code class=\"language-text\">==> Allocated addr: &lt;Address></code> have not been freed.</p>\n<p>For issues such as memory leaks, unless allocations occur extremely intermittently, it is rare for the call stack at the time the dump file is captured to contain useful information.</p>\n<p>So in many cases, live debugging, inspecting the source code, or reverse-engineering the application is more efficient than analyzing the dump file.</p>\n<p>That said, in this book we will try, as much as possible, to identify the code responsible for the memory leak by analyzing the dump file.</p>\n<p>First, with the process dump file loaded in WinDbg, run the <code class=\"language-text\">k</code> command to output a stack backtrace.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">0:000> k\n # Child-SP          RetAddr               Call Site\n00 0000003d`d1eff6e8 00007ffa`382d30ce     ntdll!NtWaitForSingleObject+0x14\n01 0000003d`d1eff6f0 00007ff6`dfe213b9     KERNELBASE!WaitForSingleObjectEx+0x8e\n02 0000003d`d1eff790 00007ff6`dfe21a40     D4C+0x13b9\n03 0000003d`d1effa50 00007ffa`38b17344     D4C+0x1a40\n04 0000003d`d1effa90 00007ffa`3a9c26b1     kernel32!BaseThreadInitThunk+0x14\n05 0000003d`d1effac0 00000000`00000000     ntdll!RtlUserThreadStart+0x21</code></pre></div>\n<p>Unfortunately, calls to functions such as <code class=\"language-text\">HeapAlloc</code>, which are used for heap allocation, were not recorded in this stack backtrace.</p>\n<p>However, although we did not deal with this in Chapters 4 and 5, many ordinary applications run as multi-threaded programs.</p>\n<p>The information you get by running the <code class=\"language-text\">k</code> command after loading a process dump into WinDbg is only the stack backtrace of the process’s main thread, so just to be safe, let’s investigate the stack backtraces of the other threads as well.</p>\n<p>Threads running inside a user-mode process can be enumerated with the <code class=\"language-text\">!threads</code> extension.<sup id=\"fnref-13\"><a href=\"#fn-13\" class=\"footnote-ref\">13</a></sup></p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/0ec34578939c0d4a8e075bd68e7e903c/0b533/app-memleak-thread-001.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 6.666666666666667%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAABCAYAAADeko4lAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAR0lEQVQI1x3KMQoAIQwAwfv/86xMQEkhhFgoWtiueN0y7NdaI6VErZVSCjln5pyYGarKWov3PH/t7ogIYwwi4vfeO3tvzjlcfZtJYFp4Q4cAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/0ec34578939c0d4a8e075bd68e7e903c/8ac56/app-memleak-thread-001.webp 240w,\n/static/0ec34578939c0d4a8e075bd68e7e903c/d3be9/app-memleak-thread-001.webp 480w,\n/static/0ec34578939c0d4a8e075bd68e7e903c/b0a15/app-memleak-thread-001.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/0ec34578939c0d4a8e075bd68e7e903c/8ff5a/app-memleak-thread-001.png 240w,\n/static/0ec34578939c0d4a8e075bd68e7e903c/e85cb/app-memleak-thread-001.png 480w,\n/static/0ec34578939c0d4a8e075bd68e7e903c/0b533/app-memleak-thread-001.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/0ec34578939c0d4a8e075bd68e7e903c/0b533/app-memleak-thread-001.png\"\n            alt=\"Output of the !threads command\"\n            title=\"Output of the !threads command\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>When we run <code class=\"language-text\">!threads</code> with the process dump we are analyzing loaded, we can confirm, as shown above, that in addition to the main thread (thread ID: 0), two more threads have been created. (If <code class=\"language-text\">No export threads found</code> appears when you run <code class=\"language-text\">!threads</code>, try running <code class=\"language-text\">!analyze -v</code> once.)</p>\n<p>If you want to see the stack backtraces of all threads running in the current process context, use the <code class=\"language-text\">~*k</code> command.</p>\n<p>You can also specify the index of a particular thread, such as <code class=\"language-text\">~1k</code> or <code class=\"language-text\">~2k</code>.</p>\n<p>Furthermore, by specifying a particular thread index and running <code class=\"language-text\">~1s</code> or <code class=\"language-text\">~2s</code>, you can switch the current thread context.</p>\n<p>In other words, running <code class=\"language-text\">~1s; k</code> also lets you see the stack backtrace of thread index 1, just like <code class=\"language-text\">~1k</code>.</p>\n<br>\n<p>~s (set the current thread):</p>\n<p><a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-s--set-current-thread-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-s—set-current-thread-</a></p>\n<br>\n<p>This time, we will use the <code class=\"language-text\">~*k</code> command to output the stack backtraces of all threads together.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">0:000> ~*k\n\n.  0  Id: 159c.10d4 Suspend: 0 Teb: 0000003d`d1ce8000 Unfrozen\n # Child-SP          RetAddr               Call Site\n00 0000003d`d1eff6e8 00007ffa`382d30ce     ntdll!NtWaitForSingleObject+0x14\n01 0000003d`d1eff6f0 00007ff6`dfe213b9     KERNELBASE!WaitForSingleObjectEx+0x8e\n02 0000003d`d1eff790 00007ff6`dfe21a40     D4C+0x13b9\n03 0000003d`d1effa50 00007ffa`38b17344     D4C+0x1a40\n04 0000003d`d1effa90 00007ffa`3a9c26b1     kernel32!BaseThreadInitThunk+0x14\n05 0000003d`d1effac0 00000000`00000000     ntdll!RtlUserThreadStart+0x21\n\n   1  Id: 159c.2390 Suspend: 0 Teb: 0000003d`d1cf0000 Unfrozen\n # Child-SP          RetAddr               Call Site\n00 0000003d`d22fe838 00007ffa`382fb4ee     ntdll!NtDelayExecution+0x14\n01 0000003d`d22fe840 00007ff6`dfe21680     KERNELBASE!SleepEx+0x9e\n02 0000003d`d22fe8e0 00007ffa`38b17344     D4C+0x1680\n03 0000003d`d22ff930 00007ffa`3a9c26b1     kernel32!BaseThreadInitThunk+0x14\n04 0000003d`d22ff960 00000000`00000000     ntdll!RtlUserThreadStart+0x21\n\n   2  Id: 159c.1018 Suspend: 0 Teb: 0000003d`d1cf2000 Unfrozen\n # Child-SP          RetAddr               Call Site\n00 0000003d`d23fea68 00007ffa`382fb4ee     ntdll!NtDelayExecution+0x14\n01 0000003d`d23fea70 00007ff6`dfe21680     KERNELBASE!SleepEx+0x9e\n02 0000003d`d23feb10 00007ffa`38b17344     D4C+0x1680\n03 0000003d`d23ffb60 00007ffa`3a9c26b1     kernel32!BaseThreadInitThunk+0x14\n04 0000003d`d23ffb90 00000000`00000000     ntdll!RtlUserThreadStart+0x21</code></pre></div>\n<p>From the output above, we can see that threads with indexes 1 and 2 are both calling <code class=\"language-text\">KERNELBASE!SleepEx</code> from <code class=\"language-text\">D4C+0x1680</code> in the same way.</p>\n<p>However, from this alone we still cannot decide which thread we should investigate first.</p>\n<p>So let’s examine the information for each thread from a slightly different angle.</p>\n<p>In WinDbg, the <code class=\"language-text\">!runaway</code> extension<sup id=\"fnref-14\"><a href=\"#fn-14\" class=\"footnote-ref\">14</a></sup> lets you obtain information about the amount of time consumed by each thread.</p>\n<p>If we run <code class=\"language-text\">!runaway 7</code> in WinDbg after loading the dump file captured this time, we get the following output. (<code class=\"language-text\">7</code> is an option flag that tells the <code class=\"language-text\">!runaway</code> extension to output all information about user-mode time consumed, kernel-mode time consumed, and elapsed time since each thread was created.)</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">0:000> !runaway 7\n\nUser Mode Time\nThread       Time\n  1:2390     0 days 0:00:27.031\n  2:1018     0 days 0:00:11.093\n  0:10d4     0 days 0:00:00.000\n\nKernel Mode Time\nThread       Time\n  1:2390     0 days 0:01:38.703\n  2:1018     0 days 0:00:01.703\n  0:10d4     0 days 0:00:00.000\n\nElapsed Time\nThread       Time\n  0:10d4     0 days 0:30:53.547\n  1:2390     0 days 0:30:45.242\n  2:1018     0 days 0:30:45.242</code></pre></div>\n<p>Looking at the output of <code class=\"language-text\">!runaway 7</code>, we can see that the thread with index 1 has consumed an unusually large amount of kernel time.</p>\n<p>In general, problems that affect system performance, such as memory leaks, are often caused by the behavior of threads that consume more system resources (= threads that consume more execution time).</p>\n<p>Also, processing related to memory operations such as heap allocation generally involves kernel-mode execution.</p>\n<p>Therefore, the thread with index 1, which is consuming more kernel time, is likely the cause of the problem, so we will prioritize investigating it.</p>\n<p>Incidentally, you can investigate the number of threads running in a process and their execution time with tools such as Process Explorer even without using WinDbg.</p>\n<p>When using Process Explorer, just as when you captured the dump file, launch Process Explorer with administrator privileges and right-click the <code class=\"language-text\">D4C.exe</code> process.</p>\n<p>Then click <code class=\"language-text\">[Properties..]</code> and open the <code class=\"language-text\">[Threads]</code> tab to inspect information about the threads running in the process, as shown below.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/d25c587fd083cbb96a9b87ad7e7ee23b/0b533/app-memleak-proexp-001.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 129.58333333333334%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAaCAYAAAC3g3x9AAAACXBIWXMAAA7EAAAOxAGVKw4bAAADhElEQVRIx9VVyY7bRhDV7xoI4AS55OAEMHLIIR+Qj0hgewzfcspJ4yDWzHg2LVzEnaIoShRFUaSGeqlXGtkTR4PEuaWAApvVXdXVtbzq3NoBxo4Dz/cxHA1lPYY1tjBJEtR1jaqq9NsI1/dM2Xq9xmazwXK5xHw+V5lt2+ik2QKTyQTT6VQ3+PUDH7HIqLRarZCmM+EUs1mqayrTUJJM9WLql3LWdR10oihEr9fDO2Eeur3t4+LiAoZh4PLyCnEc4/Tt7+idnele9/QU1ze3CALqnWE0MlS33+/DNE106NV4bCMIQ/Xo7u4Obdtiu92iKAp9YiFe8nlNs9UzeZ7rP5nny3Kt8vF4jA6VynWFdJbpBp+6qRs9EEaxPD9SeZZlcBwXYRhJaBbi+UTiHmCWzXEnDrTtbh9DL1ngx18jfPfawZevfHx7YuPp6wm+eRPh+xMDz18O8fVJgC9e+Hjys4Mnv7j46qWL5ycWnr0w8MMbOf8qxE/dOQJHDBarEkPLQ+/axDSv4MYZlpsdslUDN0pheDHSolZZXrUQMcJ0jm7vEn+87+O3bg9ukqPaApZl7Z/c1Btsmxr/mnYt6mqNal0q85+kBplZxkDP7XZ/4/aIbHfsDpF/NCiZ+tQgHlF67GJuHTX4ubTX+V8aPB6Xz+MPBtv/4Nkx+mBwVZbIFwtFG/JC1mS224Ef7lFnucx1TTRi7zdNszfIRnddT1HDcV14ngdTNixLACMIpJcD6d9Q5a7sj0YjnJ9f4PLqCoPBEFfyNQxToUzBgQZ934Mtjd/eV/x0mihItBLbSjqC3hyIHhHaXLmAHtu2JXB2o14rHlLoei4y+R6yHQpGGpapnhM8J5NYkYdPJLiSDmcfkiPI36GhkbjMGyvBN1IgiD00RzAEMLf3itc3fdyIJwxHLt4Q0g5l0963rhokthF9HXGXME6K40gUTcU+EsGW8WSMl8U+CdybSbJIfzHIGDLQQcgEhKJQyNyYYiAyHmAFEDwHw6FAvKVfynjJ0ScXaiAVlP4IXwxwOpshkeQQyZkIjglfJqMvF89ZOqK32dRYi3HaIGKpwVIED9vo0/Zj8DmAzmVwsSwKybilCXOQyRQcDPZDTZMrIenMxBN6xKf/E7N8PEF005vAdCM40X68Mr4cvyynDheLB13yGLMalvkCAzfF2+sxuu9lzNoJAqlhjlFWBF/yJ2KGtBuH0SWpAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/d25c587fd083cbb96a9b87ad7e7ee23b/8ac56/app-memleak-proexp-001.webp 240w,\n/static/d25c587fd083cbb96a9b87ad7e7ee23b/d3be9/app-memleak-proexp-001.webp 480w,\n/static/d25c587fd083cbb96a9b87ad7e7ee23b/b0a15/app-memleak-proexp-001.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/d25c587fd083cbb96a9b87ad7e7ee23b/8ff5a/app-memleak-proexp-001.png 240w,\n/static/d25c587fd083cbb96a9b87ad7e7ee23b/e85cb/app-memleak-proexp-001.png 480w,\n/static/d25c587fd083cbb96a9b87ad7e7ee23b/0b533/app-memleak-proexp-001.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/d25c587fd083cbb96a9b87ad7e7ee23b/0b533/app-memleak-proexp-001.png\"\n            alt=\"Viewing thread information in Process Explorer\"\n            title=\"Viewing thread information in Process Explorer\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<h2 id=\"analyzing-what-each-thread-is-doing\" style=\"position:relative;\"><a href=\"#analyzing-what-each-thread-is-doing\" aria-label=\"analyzing what each thread is doing permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Analyzing what each thread is doing</h2>\n<p>By this point in the investigation, we have identified the following information about the <code class=\"language-text\">D4C.exe</code> memory leak issue.</p>\n<ul>\n<li>The heap region in the <code class=\"language-text\">D4C.exe</code> process has ballooned.</li>\n<li>The memory of many heap entries that were allocated and never freed contains the string <code class=\"language-text\">==> Allocated addr: &lt;Address></code>.</li>\n<li>Three threads are running in the <code class=\"language-text\">D4C.exe</code> process, and in particular the thread with index 1 has consumed an unusually large amount of kernel-mode execution time.</li>\n</ul>\n<p>From here, we will identify the code that is actually causing the process’s heap region to balloon and triggering the memory leak.</p>\n<p>However, unlike the crash analyses we have performed so far, a dump file captured by the user at an arbitrary timing does not necessarily contain convenient information about the execution of the code that caused the problem.</p>\n<p>This is because the information contained in a dump file is, after all, nothing more than the state of memory at the moment the dump was captured.</p>\n<p>In such cases, if you want to identify the code that writes to the heap region, it is often more effective to do live debugging or source-code analysis, or to use a decompiler such as Ghidra, which we used in Chapters 4 and 5.</p>\n<p>There are multiple possible ways to identify the code that writes to the heap region, but in this book we will proceed with the following approach.</p>\n<ol>\n<li>Identify the offset in the application’s data region where the string <code class=\"language-text\">==> Allocated addr:</code> is hardcoded.</li>\n<li>Use a decompiler to identify the code that references the data at the offset found in step 1, and thereby identify the code that writes the string <code class=\"language-text\">==> Allocated addr: &lt;Address></code> into memory.</li>\n</ol>\n<p>As we confirmed in the sections above, the memory inside the heap regions allocated this time contains the string <code class=\"language-text\">==> Allocated addr: &lt;Address></code>, and the <code class=\"language-text\">==> Allocated addr:</code> part was the same in every heap region.</p>\n<p>In other words, unless the program is obfuscated, it is reasonable to assume that the text <code class=\"language-text\">==> Allocated addr:</code> is hardcoded in the program.</p>\n<p>Data such as text hardcoded in a program is typically placed in the <code class=\"language-text\">.rdata</code> region (initialized read-only data) of the running process.<sup id=\"fnref-15\"><a href=\"#fn-15\" class=\"footnote-ref\">15</a></sup></p>\n<p>So first, in WinDbg with the process dump file loaded, we will scan the <code class=\"language-text\">.rdata</code> region to identify the address where the text <code class=\"language-text\">==> Allocated addr:</code> is hardcoded.</p>\n<p>To scan the <code class=\"language-text\">.rdata</code> region, we first need to identify the target address range, so let’s display the section header information for <code class=\"language-text\">D4C.exe</code> with the <code class=\"language-text\">!dh -s</code> command.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">0:000> !dh -s !D4C\n\nSECTION HEADER #1\n .text name\n  15EC virtual size\n  1000 virtual address\n  1600 size of raw data\n   400 file pointer to raw data\n     0 file pointer to relocation table\n     0 file pointer to line numbers\n     0 number of relocations\n     0 number of line numbers\n60000020 flags\n       Code\n       (no align specified)\n       Execute Read\n\nSECTION HEADER #2\n.rdata name\n  343A virtual size\n  3000 virtual address\n  3600 size of raw data\n  1A00 file pointer to raw data\n     0 file pointer to relocation table\n     0 file pointer to line numbers\n     0 number of relocations\n     0 number of line numbers\n40000040 flags\n       Initialized Data\n       (no align specified)\n       Read Only\n\n{{ omitted }}\n\nSECTION HEADER #3\n .data name\n   638 virtual size\n  7000 virtual address\n   200 size of raw data\n  5000 file pointer to raw data\n     0 file pointer to relocation table\n     0 file pointer to line numbers\n     0 number of relocations\n     0 number of line numbers\nC0000040 flags\n       Initialized Data\n       (no align specified)\n       Read Write\n\n{{ omitted }}</code></pre></div>\n<p>When we ran <code class=\"language-text\">!dh -s !D4C</code> in WinDbg with this process dump loaded, we found, as shown above, that the <code class=\"language-text\">.rdata</code> section had a <code class=\"language-text\">virtual address</code> of <code class=\"language-text\">0x3000</code> and an aligned size of <code class=\"language-text\">0x3600</code>.</p>\n<p>In other words, we can conclude that the <code class=\"language-text\">.rdata</code> section in this process dump exists in the range starting at <code class=\"language-text\">!D4C+0x3000</code> (the address obtained by adding <code class=\"language-text\">0x3000</code> to the image base address of <code class=\"language-text\">D4C.exe</code>) and extending for <code class=\"language-text\">0x3600</code> bytes.</p>\n<p>Now that we know the address range of the <code class=\"language-text\">.rdata</code> section, next let’s use the <code class=\"language-text\">s</code> command to search for text within that range.<sup id=\"fnref-16\"><a href=\"#fn-16\" class=\"footnote-ref\">16</a></sup></p>\n<p>When using the <code class=\"language-text\">s</code> command to search for ASCII text within a specified address range, run <code class=\"language-text\">s -a &lt;search start address> L&lt;search size> \"&lt;ASCII text to search for>\"</code>.\n(<code class=\"language-text\">-a</code> specifies that the search target is an ASCII string. If you want to search for a Unicode string, use the <code class=\"language-text\">-u</code> option.)</p>\n<p>To search for the text <code class=\"language-text\">==> Allocated addr:</code> in the <code class=\"language-text\">.rdata</code> section inside the <code class=\"language-text\">D4C.exe</code> process, run <code class=\"language-text\">s -a !D4C+0x3000 L0x3600 \"==> Allocated addr:\"</code>.</p>\n<p>When we actually ran that command, we confirmed that the target string was defined at address <code class=\"language-text\">0x7ff6dfe236b0</code>, as shown below.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">0:000> s -a !D4C+0x3000 L0x3600 \"==> Allocated addr:\" \n00007ff6`dfe236b0  3d 3d 3e 20 41 6c 6c 6f-63 61 74 65 64 20 61 64  ==> Allocated ad</code></pre></div>\n<p>The output of the <code class=\"language-text\">s</code> command above did not show the full text that was defined, so next let’s use the <code class=\"language-text\">da</code> command to display the text stored at that address.<sup id=\"fnref-17\"><a href=\"#fn-17\" class=\"footnote-ref\">17</a></sup></p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">0:000> da 00007ff6dfe236b0\n00007ff6`dfe236b0  \"==> Allocated addr: 0x%08x.\"</code></pre></div>\n<p>This confirms that the hardcoded text <code class=\"language-text\">==> Allocated addr: 0x%08x.</code> exists at address <code class=\"language-text\">0x7ff6dfe236b0</code>.</p>\n<p>Finally, we will identify the relative virtual address (RVA) where this text is hardcoded.</p>\n<p>You can identify the RVA by subtracting the image base address of <code class=\"language-text\">D4C.exe</code> from the address <code class=\"language-text\">0x7ff6dfe236b0</code>, where this text is hardcoded.</p>\n<div class=\"gatsby-highlight\" data-language=\"text\"><pre class=\"language-text\"><code class=\"language-text\">0:000> ? 0x7ff6dfe236b0 - !D4C\nEvaluate expression: 14000 = 00000000`000036b0</code></pre></div>\n<p>By calculating the address with the command above, we can identify that the RVA where the target text is defined is <code class=\"language-text\">0x36b0</code>.</p>\n<p>Now that we know the offset where the string <code class=\"language-text\">==> Allocated addr:</code> is hardcoded, we will continue by using the Ghidra decompiler to identify the code that writes this text to the heap region.</p>\n<p>After launching Ghidra and loading <code class=\"language-text\">D4C.exe</code> using the same procedure as in Chapters 4 and 5, press <code class=\"language-text\">[g]</code> on the keyboard to open the GoTo window.</p>\n<p>Next, enter the value obtained by adding the offset <code class=\"language-text\">0x36b0</code> we identified earlier to the default image base address <code class=\"language-text\">0x140000000</code> that Ghidra uses when loading <code class=\"language-text\">D4C.exe</code>, and click <code class=\"language-text\">[OK]</code>.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/231815079ca16cb22ceb06ce7dbd0ec7/0b533/app-leak-ghidra-001.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 32.916666666666664%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAHCAYAAAAIy204AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABT0lEQVQoz42R646cMAxGef+Xa6Vqq6HMDLvcZoAQEggQrmcN/V/V0lEcy/b3RQlSNZPpg8IcZNXKPZ+IspEwdYSZ45b23BLHsxwp7MZTdcSNk3zloazQ/a0pQ6IGglIP1AbeeuVZlOSVQ7uNV+tEyJI2hq9ak7UdVT9RuwnlPGbc5D5SXzWPkrzpPUHfDXDAsgxE8QeqqjBtgxEha6aLpu449o0zhsUxLiPHsdHPPW52DMJ5+kUWPh8Z0wTz7Pl1i/n5+84jfRHGRrD8+bT8uClpnvmfCKzpRe106IkeMWEYUdUKpRuSNOVLyMsK75drYBdnq7g9ZGjdVjbJT9Z9Zd93AudGaQZrJ4zRaNORlJqybijynLZtabUmfzc01lG6mt47Gd6wkxU6Ot9d5zCNBPcoYXBcDowxvOSHnm+hePEZx7LQiJi9nny6WMTVv+IbpBMXQh2xrMAAAAAASUVORK5CYII='); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/231815079ca16cb22ceb06ce7dbd0ec7/8ac56/app-leak-ghidra-001.webp 240w,\n/static/231815079ca16cb22ceb06ce7dbd0ec7/d3be9/app-leak-ghidra-001.webp 480w,\n/static/231815079ca16cb22ceb06ce7dbd0ec7/b0a15/app-leak-ghidra-001.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/231815079ca16cb22ceb06ce7dbd0ec7/8ff5a/app-leak-ghidra-001.png 240w,\n/static/231815079ca16cb22ceb06ce7dbd0ec7/e85cb/app-leak-ghidra-001.png 480w,\n/static/231815079ca16cb22ceb06ce7dbd0ec7/0b533/app-leak-ghidra-001.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/231815079ca16cb22ceb06ce7dbd0ec7/0b533/app-leak-ghidra-001.png\"\n            alt=\"Jumping to the specified address in Ghidra&#39;s GoTo window\"\n            title=\"Jumping to the specified address in Ghidra&#39;s GoTo window\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>This jumps to address <code class=\"language-text\">0x1400036b0</code>, where we can confirm in Ghidra as well that the text <code class=\"language-text\">==> Allocated addr: 0x%08x.</code> is hardcoded.</p>\n<p>If you inspect the text at address <code class=\"language-text\">0x1400036b0</code> in Ghidra’s Listing window, you can also see <code class=\"language-text\">XREF[1]: FUN_1400015a0:14000161d(*)</code> displayed on the right side.</p>\n<p>This indicates the address of the code that references this data.</p>\n<p>If you double-click <code class=\"language-text\">XREF[1]: FUN_1400015a0:14000161d(*)</code> in Ghidra, you can jump to address <code class=\"language-text\">0x14000161d</code>, which loads the text at <code class=\"language-text\">0x1400036b0</code>, as shown below.</p>\n<p><span\n      class=\"gatsby-resp-image-wrapper\"\n      style=\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 500px; \"\n    >\n      <a\n    class=\"gatsby-resp-image-link\"\n    href=\"/static/586d87bba597b1dda0d225d755625bc6/0b533/app-leak-ghidra-002.png\"\n    style=\"display: block\"\n    target=\"_blank\"\n    rel=\"noopener\"\n  >\n    <span\n    class=\"gatsby-resp-image-background-image\"\n    style=\"padding-bottom: 62.5%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAANCAYAAACpUE5eAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACbUlEQVQ4y21Ta2/TQBDM//878KlfKvEFCUEFVaGlVG2a2Oe347N9D98jw5wdUZDYZJWzvJmdndnbXV094v27b7i+3uPmJsPDg8DzS4GuG1DXNeqmRdNU+H53j48fbvDl0y2+fr7Dj9tH/Lx7wq/7Zzw97LF/OSA7ZtiB0XcNTifALkAIHkNbYR419OxwPmONqm6wWB7Sc+DX8+iY/I1+e06xs0Q5vOYohIOUDtNk0BcD1GShZqZasCweWV6hbjt4PyOeA3H/82H3nXMOddWg7z3/HKD1gmk+wbmFneOF0hn54RVHITHPFcyiVjaJfQL5O3fLQoBpJlBksYNWDs5a+BA4foQhcAIXxz0ZDjhNLTTfx5DA4tbvr+DIFnkmLiN7ghrUZcUmlucFSjtY65Ad9uh6gU5JtHLEME7QbsLiDbwjAe0RXNgAq4L6VJ4gHpYAsiZjY8ks/OmcHw9kKDEqjZk1KZ1xNIN6xohz4MiRIytNhqJBXnh0J4dBWvTlQAYGkhKMzEl5CFGibwSqtkVWjcjLGkpOlMfRpE2/JOrOmDRygTz3OA00hmM2xxmy1QSbqKFHZOcsz1HmrOOKlTJHddqjHRpIMlaLhJbqbWTBwoIMx9Gvu9eXGnJgobLryqTRRVGiLCzKocIwN6xL7AycDjQovLm8akj6dU0NZw9Dl8dmhFWGzlsYjuS5PmVZYJxGKDOv7p+xgcR0jud/XS5pStMkwABLocuiheRNMYaM9QaYZCmp3TgPNG+iKYoGjmToVtBtLy8appGF8OvaaGpY86Y0HXWkQWnRUxwFGY50lbsXuISedy2uGTdDLoC/AaZ458RbcDXbAAAAAElFTkSuQmCC'); background-size: cover; display: block;\"\n  ></span>\n  <picture>\n          <source\n              srcset=\"/static/586d87bba597b1dda0d225d755625bc6/8ac56/app-leak-ghidra-002.webp 240w,\n/static/586d87bba597b1dda0d225d755625bc6/d3be9/app-leak-ghidra-002.webp 480w,\n/static/586d87bba597b1dda0d225d755625bc6/b0a15/app-leak-ghidra-002.webp 500w\"\n              sizes=\"(max-width: 500px) 100vw, 500px\"\n              type=\"image/webp\"\n            />\n          <source\n            srcset=\"/static/586d87bba597b1dda0d225d755625bc6/8ff5a/app-leak-ghidra-002.png 240w,\n/static/586d87bba597b1dda0d225d755625bc6/e85cb/app-leak-ghidra-002.png 480w,\n/static/586d87bba597b1dda0d225d755625bc6/0b533/app-leak-ghidra-002.png 500w\"\n            sizes=\"(max-width: 500px) 100vw, 500px\"\n            type=\"image/png\"\n          />\n          <img\n            class=\"gatsby-resp-image-image\"\n            src=\"/static/586d87bba597b1dda0d225d755625bc6/0b533/app-leak-ghidra-002.png\"\n            alt=\"Identifying the code that writes to the heap\"\n            title=\"Identifying the code that writes to the heap\"\n            loading=\"lazy\"\n            style=\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\"\n          />\n        </picture>\n  </a>\n    </span></p>\n<p>As a result of decompiling the code around this address in Ghidra, we obtained the following pseudocode.</p>\n<div class=\"gatsby-highlight\" data-language=\"c\"><pre class=\"language-c\"><code class=\"language-c\"><span class=\"token keyword\">while</span><span class=\"token punctuation\">(</span> true <span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n   _Dst <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">char</span> <span class=\"token operator\">*</span><span class=\"token punctuation\">)</span><span class=\"token function\">malloc</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">(</span>longlong<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span><span class=\"token punctuation\">)</span>param_1<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>_Dst <span class=\"token operator\">==</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">char</span> <span class=\"token operator\">*</span><span class=\"token punctuation\">)</span><span class=\"token number\">0x0</span><span class=\"token punctuation\">)</span> <span class=\"token keyword\">break</span><span class=\"token punctuation\">;</span>\n      <span class=\"token function\">printf</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"Count: %d\\n\"</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">(</span>ulonglong<span class=\"token punctuation\">)</span>uVar2<span class=\"token punctuation\">,</span>param_3<span class=\"token punctuation\">,</span>param_4<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n   param_4 <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>ulonglong<span class=\"token punctuation\">)</span>_Dst <span class=\"token operator\">&amp;</span> <span class=\"token number\">0xffffffff</span><span class=\"token punctuation\">;</span>\n   _SizeInBytes <span class=\"token operator\">=</span> <span class=\"token punctuation\">(</span>ulonglong<span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">(</span>param_1 <span class=\"token operator\">-</span> <span class=\"token number\">1</span><span class=\"token punctuation\">)</span>\n\n   pcVar3 <span class=\"token operator\">=</span> <span class=\"token string\">\"==> Allocated addr: 0x%08x\\n\"</span><span class=\"token punctuation\">;</span>\n   <span class=\"token function\">FUN_140001540</span><span class=\"token punctuation\">(</span>local_1030<span class=\"token punctuation\">,</span>_SizeInBytes<span class=\"token punctuation\">,</span><span class=\"token string\">\"==> Allocated addr: 0x%08x\\n\"</span><span class=\"token punctuation\">,</span>param_4<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n   <span class=\"token function\">printf</span><span class=\"token punctuation\">(</span><span class=\"token operator\">&amp;</span>DAT_1400036cc<span class=\"token punctuation\">,</span>local_1030<span class=\"token punctuation\">,</span>pcVar3<span class=\"token punctuation\">,</span>param_4<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token function\">printf</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"==> Total allocated size: 0x%08x\\n\"</span><span class=\"token punctuation\">,</span><span class=\"token punctuation\">(</span>ulonglong<span class=\"token punctuation\">)</span>uVar1<span class=\"token punctuation\">,</span>pcVar3<span class=\"token punctuation\">,</span>param_4<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n   param_3 <span class=\"token operator\">=</span> local_1030<span class=\"token punctuation\">;</span>\n   <span class=\"token function\">strcpy_s</span><span class=\"token punctuation\">(</span>_Dst<span class=\"token punctuation\">,</span>_SizeInBytes<span class=\"token punctuation\">,</span>param_3<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n   <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span><span class=\"token number\">0x1fffffff</span> <span class=\"token operator\">&lt;</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">int</span><span class=\"token punctuation\">)</span>uVar1<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token function\">printf</span><span class=\"token punctuation\">(</span><span class=\"token string\">\"==> Slow Down...\\n\"</span><span class=\"token punctuation\">,</span>_SizeInBytes<span class=\"token punctuation\">,</span>param_3<span class=\"token punctuation\">,</span>param_4<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n      <span class=\"token function\">Sleep</span><span class=\"token punctuation\">(</span><span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n   <span class=\"token punctuation\">}</span>\n\n   uVar2 <span class=\"token operator\">=</span> uVar2 <span class=\"token operator\">+</span> <span class=\"token number\">1</span><span class=\"token punctuation\">;</span>\n   uVar1 <span class=\"token operator\">=</span> uVar1 <span class=\"token operator\">+</span> param_1<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div>\n<p>By analyzing this pseudocode, we can see that inside the <code class=\"language-text\">while</code> loop, the program repeatedly allocates heap memory with the <code class=\"language-text\">malloc</code> function and writes to it with the <code class=\"language-text\">strcpy_s</code> function, yet no code is defined to free the allocated heap.</p>\n<p>With that, we have identified the code responsible for the user-mode memory leak in <code class=\"language-text\">D4C.exe</code>.</p>\n<h2 id=\"summary-of-chapter-6\" style=\"position:relative;\"><a href=\"#summary-of-chapter-6\" aria-label=\"summary of chapter 6 permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Summary of Chapter 6</h2>\n<p>In this chapter, as an example of investigating the cause of a non-crash problem from a dump file, we analyzed a user-mode application memory leak issue.</p>\n<p>In Chapter 7, the final chapter of this book, we will investigate the same memory leak issue covered in this chapter, this time from a full system memory dump.</p>\n<p>Even though we casually refer to both of them as “dump files,” the analysis methods and investigative approach differ greatly between a user-mode process dump and a full system memory dump.</p>\n<p>Compared with the crash-dump analysis covered in Chapters 4 and 5, this chapter may have felt a little more difficult, but I think investigating problems like this is one of the real pleasures of dump analysis, so I hope you will enjoy reading through to the very end.</p>\n<h2 id=\"links-to-each-chapter\" style=\"position:relative;\"><a href=\"#links-to-each-chapter\" aria-label=\"links to each chapter permalink\" class=\"anchor before\"><svg aria-hidden=\"true\" focusable=\"false\" height=\"16\" version=\"1.1\" viewBox=\"0 0 16 16\" width=\"16\"><path fill-rule=\"evenodd\" d=\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\"></path></svg></a>Links to each chapter</h2>\n<ul>\n<li><a href=\"/magical-windbg-vol1-00-en\">Preface</a></li>\n<li><a href=\"/magical-windbg-vol1-01-en\">Chapter 1: Environment Setup</a></li>\n<li><a href=\"/magical-windbg-vol1-02-en\">Chapter 2: Basic WinDbg Operations</a></li>\n<li><a href=\"/magical-windbg-vol1-03-en\">Chapter 3: Prerequisites for Analysis</a></li>\n<li><a href=\"/magical-windbg-vol1-04-en\">Chapter 4: Analyzing an Application Crash Dump</a></li>\n<li><a href=\"/magical-windbg-vol1-05-en\">Chapter 5: Analyzing a Full Memory Dump from a System Crash</a></li>\n<li><a href=\"/magical-windbg-vol1-06-en\">Chapter 6: Investigating a User-Mode Application Memory Leak from a Process Dump</a></li>\n<li><a href=\"/magical-windbg-vol1-07-en\">Chapter 7: Investigating a User-Mode Memory Leak from a Full Memory Dump</a></li>\n<li><a href=\"/magical-windbg-vol1-50-en\">Appendix A: WinDbg Tips</a></li>\n<li><a href=\"/magical-windbg-vol1-51-en\">Appendix B: Analyzing Crash Dumps with Volatility 3</a></li>\n<li><a href=\"/magical-windbg-vol1-99\">Afterword</a></li>\n</ul>\n<div class=\"footnotes\">\n<hr>\n<ol>\n<li id=\"fn-1\">\n<p>Virtual memory and physical memory <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/virtual-and-physical-memory\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/virtual-and-physical-memory</a></p>\n<a href=\"#fnref-1\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-2\">\n<p>Bug Check <code class=\"language-text\">0x8E: KERNEL_MODE_EXCEPTION_NOT_HANDLED</code> <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/bug-check-0x8e--kernel-mode-exception-not-handled\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/bug-check-0x8e—kernel-mode-exception-not-handled</a></p>\n<a href=\"#fnref-2\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-3\">\n<p><em>Windows Internals, 7th Edition, Part 1</em>, p.402 (by Pavel Yosifovich, Alex Ionescu, Mark E. Russinovich, David A. Solomon / translated by 山内 和朗 / 日系 BP 社 / 2018)</p>\n<a href=\"#fnref-3\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-4\">\n<p><code class=\"language-text\">HeapCreate</code> function <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/heapapi/nf-heapapi-heapcreate\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows/win32/api/heapapi/nf-heapapi-heapcreate</a></p>\n<a href=\"#fnref-4\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-5\">\n<p><code class=\"language-text\">HeapAlloc</code> function <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/api/heapapi/nf-heapapi-heapalloc\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows/win32/api/heapapi/nf-heapapi-heapalloc</a></p>\n<a href=\"#fnref-5\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-6\">\n<p><em>Windows Internals, 7th Edition, Part 1</em>, p.366 (by Pavel Yosifovich, Alex Ionescu, Mark E. Russinovich, David A. Solomon / translated by 山内 和朗 / 日系 BP 社 / 2018)</p>\n<a href=\"#fnref-6\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-7\">\n<p><code class=\"language-text\">!heap</code> extension <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-heap\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-heap</a></p>\n<a href=\"#fnref-7\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-8\">\n<p><em>Windows Internals, 7th Edition, Part 1</em>, p.368 (by Pavel Yosifovich, Alex Ionescu, Mark E. Russinovich, David A. Solomon / translated by 山内 和朗 / 日系 BP 社 / 2018)</p>\n<a href=\"#fnref-8\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-9\">\n<p><em>Windows Internals, 7th Edition, Part 1</em>, p.372 (by Pavel Yosifovich, Alex Ionescu, Mark E. Russinovich, David A. Solomon / translated by 山内 和朗 / 日系 BP 社 / 2018)</p>\n<a href=\"#fnref-9\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-10\">\n<p><em>Advanced Windows Debugging, 1st Edition</em>, p.276 (by Mario Hewardt, Daniel Pravat / Addison-Wesley Professional / 2007)</p>\n<a href=\"#fnref-10\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-11\">\n<p><em>Windows Internals, 7th Edition, Part 1</em>, p.406 (by Pavel Yosifovich, Alex Ionescu, Mark E. Russinovich, David A. Solomon / translated by 山内 和朗 / 日系 BP 社 / 2018)</p>\n<a href=\"#fnref-11\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-12\">\n<p><em>Windows Dump no Gokui: When an Error Occurs, Start with Dump Analysis!</em>, p.120 (by 上原 祥市 / ASCII Media Works / 2008)</p>\n<a href=\"#fnref-12\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-13\">\n<p><code class=\"language-text\">!threads</code> extension <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-thread\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-thread</a></p>\n<a href=\"#fnref-13\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-14\">\n<p><code class=\"language-text\">!runaway</code> extension <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-runaway\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/-runaway</a></p>\n<a href=\"#fnref-14\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-15\">\n<p>PE format <a href=\"https://learn.microsoft.com/ja-jp/windows/win32/debug/pe-format\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows/win32/debug/pe-format</a></p>\n<a href=\"#fnref-15\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-16\">\n<p><code class=\"language-text\">s</code> (search memory) <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/s--search-memory-\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/s—search-memory-</a></p>\n<a href=\"#fnref-16\" class=\"footnote-backref\">↩</a>\n</li>\n<li id=\"fn-17\">\n<p><code class=\"language-text\">d</code>, <code class=\"language-text\">da</code>, <code class=\"language-text\">db</code>, <code class=\"language-text\">dc</code>, <code class=\"language-text\">dd</code>, <code class=\"language-text\">dD</code>, <code class=\"language-text\">df</code>, <code class=\"language-text\">dp</code>, <code class=\"language-text\">dq</code>, <code class=\"language-text\">du</code>, <code class=\"language-text\">dw</code>, <code class=\"language-text\">dyb</code>, <code class=\"language-text\">dyd</code> (display memory) <a href=\"https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/d--da--db--dc--dd--dd--df--dp--dq--du--dw--dw--dyb--dyd--display-memor\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">https://learn.microsoft.com/ja-jp/windows-hardware/drivers/debugger/d—da—db—dc—dd—dd—df—dp—dq—du—dw—dw—dyb—dyd—display-memor</a></p>\n<a href=\"#fnref-17\" class=\"footnote-backref\">↩</a>\n</li>\n</ol>\n</div>","fields":{"slug":"/magical-windbg-vol1-06-en","tagSlugs":["/tag/magical-win-dbg/","/tag/windows/","/tag/win-dbg/","/tag/english/"]},"frontmatter":{"date":"2023-11-15","description":"This is the web edition of Magical WinDbg - Enjoying Windows Dump Analysis and Troubleshooting by Feel - VOL.1, distributed at Tech Book Fest 15.","tags":["Magical WinDbg","Windows","WinDbg","English"],"title":"Magical WinDbg VOL.1 [Chapter 6: Investigating a User-Mode Application Memory Leak from a Process Dump]","socialImage":{"publicURL":"/static/2dbf3e09d59db889dc9dc41adcc8e827/magical-windbg-vol1.png"}}}},"pageContext":{"slug":"/magical-windbg-vol1-06-en"}},"staticQueryHashes":["251939775","401334301","825871152"]}