 <p><strong>TL;DR</strong> - In the code snippet shown above, there is no memory leak.</p> <blockquote> <p><strong><em>Do I need to use malloc instead of hardcoded size of array?</em></strong></p> </blockquote> <p>I think, you got confused by the possible <em>underuse</em> of <code>char buffer[10000];</code> and <code>char error_msg[10000];</code>. These arrays are <strong>not</strong> allocated dynamically. Even the arrays are not used to their fullest capacities, there is no memory leak here.</p> <p>Also, as Mr. <strong>@Vlad</strong> metioned rightly about another <em>much possible</em> issue in your case, <code>actual_error_msg</code> being a <em>global</em>, if the <code>trimwhitespace()</code> function does not have a return value which is having a <em>global</em> scope, (i.e., stays valid after the <code>a()</code> has finished execution), it may possibly lead to <a href="https://en.wikipedia.org/wiki/Undefined_behavior" rel="nofollow">undefined behaviour</a>.</p> <p>To avoid that, make sure, <code>trimwhitespace()</code> function is either returning <sup>(assuming return type is <code>char *</code>)</sup></p> <ul> <li>a pointer with dynamic memory allocation (Preferred)</li> <li>base address of a <code>static</code> array. (bad practice, but will work)</li> </ul> <hr> <p>To elaborate, from the <a href="https://en.wikipedia.org/wiki/Memory_leak" rel="nofollow">Wikipedia</a> article about "memory leak"</p> <blockquote> <p>In computer science, a "memory leak" is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in such a way that memory which is no longer needed is not released. ...</p> </blockquote> <p>and</p> <blockquote> <p>.. Typically, a memory leak occurs because dynamically allocated memory has become unreachable. ...</p> </blockquote> <p>When memory is being allocated by your compiler, there is no scope of memory leak, as the memory (de)allocation is managed by the compiler.</p> <p>OTOH, with <a href="https://en.wikipedia.org/wiki/Memory_management#DYNAMIC" rel="nofollow">dynamic memory allocation</a>, allocation of memory is performed at <em>runtime</em>. Compiler has no information about the allocation, memory is allocated <em>programatically</em>, hence need to be <em>freed</em> programatically, also. Failing to do so leads to the "memory leak".</p>