mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
721 lines
61 KiB
HTML
721 lines
61 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
|
||
|
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
|
||
|
<meta name="generator" content="Doxygen 1.9.1"/>
|
||
|
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
||
|
<title>Algorithms_in_C: developer_tools/malloc_dbg.c File Reference</title>
|
||
|
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
|
||
|
<script type="text/javascript" src="../../jquery.js"></script>
|
||
|
<script type="text/javascript" src="../../dynsections.js"></script>
|
||
|
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
|
||
|
<script type="text/javascript" src="../../resize.js"></script>
|
||
|
<script type="text/javascript" src="../../navtreedata.js"></script>
|
||
|
<script type="text/javascript" src="../../navtree.js"></script>
|
||
|
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
|
||
|
<script type="text/javascript" src="../../search/searchdata.js"></script>
|
||
|
<script type="text/javascript" src="../../search/search.js"></script>
|
||
|
<script type="text/x-mathjax-config">
|
||
|
MathJax.Hub.Config({
|
||
|
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
|
||
|
jax: ["input/TeX","output/HTML-CSS"],
|
||
|
});
|
||
|
</script>
|
||
|
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
|
||
|
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
|
||
|
</head>
|
||
|
<body>
|
||
|
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
|
||
|
<div id="titlearea">
|
||
|
<table cellspacing="0" cellpadding="0">
|
||
|
<tbody>
|
||
|
<tr style="height: 56px;">
|
||
|
<td id="projectalign" style="padding-left: 0.5em;">
|
||
|
<div id="projectname">Algorithms_in_C
|
||
|
 <span id="projectnumber">1.0.0</span>
|
||
|
</div>
|
||
|
<div id="projectbrief">Set of algorithms implemented in C.</div>
|
||
|
</td>
|
||
|
</tr>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
</div>
|
||
|
<!-- end header part -->
|
||
|
<!-- Generated by Doxygen 1.9.1 -->
|
||
|
<script type="text/javascript">
|
||
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
||
|
var searchBox = new SearchBox("searchBox", "../../search",false,'Search','.html');
|
||
|
/* @license-end */
|
||
|
</script>
|
||
|
<script type="text/javascript" src="../../menudata.js"></script>
|
||
|
<script type="text/javascript" src="../../menu.js"></script>
|
||
|
<script type="text/javascript">
|
||
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
||
|
$(function() {
|
||
|
initMenu('../../',true,false,'search.php','Search');
|
||
|
$(document).ready(function() { init_search(); });
|
||
|
});
|
||
|
/* @license-end */</script>
|
||
|
<div id="main-nav"></div>
|
||
|
</div><!-- top -->
|
||
|
<div id="side-nav" class="ui-resizable side-nav-resizable">
|
||
|
<div id="nav-tree">
|
||
|
<div id="nav-tree-contents">
|
||
|
<div id="nav-sync" class="sync"></div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div id="splitbar" style="-moz-user-select:none;"
|
||
|
class="ui-resizable-handle">
|
||
|
</div>
|
||
|
</div>
|
||
|
<script type="text/javascript">
|
||
|
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
|
||
|
$(document).ready(function(){initNavTree('db/d84/malloc__dbg_8c.html','../../'); initResizable(); });
|
||
|
/* @license-end */
|
||
|
</script>
|
||
|
<div id="doc-content">
|
||
|
<!-- window showing the filter options -->
|
||
|
<div id="MSearchSelectWindow"
|
||
|
onmouseover="return searchBox.OnSearchSelectShow()"
|
||
|
onmouseout="return searchBox.OnSearchSelectHide()"
|
||
|
onkeydown="return searchBox.OnSearchSelectKey(event)">
|
||
|
</div>
|
||
|
|
||
|
<!-- iframe showing the search results (closed by default) -->
|
||
|
<div id="MSearchResultsWindow">
|
||
|
<iframe src="javascript:void(0)" frameborder="0"
|
||
|
name="MSearchResults" id="MSearchResults">
|
||
|
</iframe>
|
||
|
</div>
|
||
|
|
||
|
<div class="header">
|
||
|
<div class="summary">
|
||
|
<a href="#nested-classes">Data Structures</a> |
|
||
|
<a href="#typedef-members">Typedefs</a> |
|
||
|
<a href="#func-members">Functions</a> |
|
||
|
<a href="#var-members">Variables</a> </div>
|
||
|
<div class="headertitle">
|
||
|
<div class="title">malloc_dbg.c File Reference</div> </div>
|
||
|
</div><!--header-->
|
||
|
<div class="contents">
|
||
|
|
||
|
<p>This file contains malloc_dbg, calloc_dbg, free_dbg and printLeaks implementations.
|
||
|
<a href="#details">More...</a></p>
|
||
|
<div class="textblock"><code>#include <stdlib.h></code><br />
|
||
|
<code>#include <stdio.h></code><br />
|
||
|
<code>#include <string.h></code><br />
|
||
|
<code>#include "<a class="el" href="../../d2/ddd/malloc__dbg_8h_source.html">malloc_dbg.h</a>"</code><br />
|
||
|
</div><div class="textblock"><div class="dynheader">
|
||
|
Include dependency graph for malloc_dbg.c:</div>
|
||
|
<div class="dyncontent">
|
||
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d7/d70/malloc__dbg_8c__incl.svg" width="374" height="127"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div><table class="memberdecls">
|
||
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
|
||
|
Data Structures</h2></td></tr>
|
||
|
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct  </td><td class="memItemRight" valign="bottom"><a class="el" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">MEMORY_INFORMATION</a></td></tr>
|
||
|
<tr class="memdesc:"><td class="mdescLeft"> </td><td class="mdescRight">For the malloc, calloc and free functions. <a href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#details">More...</a><br /></td></tr>
|
||
|
<tr class="separator:"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
</table><table class="memberdecls">
|
||
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="typedef-members"></a>
|
||
|
Typedefs</h2></td></tr>
|
||
|
<tr class="memitem:ab6619fb17769f2e4e2e36c9ef2dda3c6"><td class="memItemLeft" align="right" valign="top">typedef struct <a class="el" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">MEMORY_INFORMATION</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d84/malloc__dbg_8c.html#ab6619fb17769f2e4e2e36c9ef2dda3c6">mem_info</a></td></tr>
|
||
|
<tr class="memdesc:ab6619fb17769f2e4e2e36c9ef2dda3c6"><td class="mdescLeft"> </td><td class="mdescRight">For the malloc, calloc and free functions. <a href="../../db/d84/malloc__dbg_8c.html#ab6619fb17769f2e4e2e36c9ef2dda3c6">More...</a><br /></td></tr>
|
||
|
<tr class="separator:ab6619fb17769f2e4e2e36c9ef2dda3c6"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
</table><table class="memberdecls">
|
||
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
|
||
|
Functions</h2></td></tr>
|
||
|
<tr class="memitem:afae235c0e32e4c8b7d67117da5f78946"><td class="memItemLeft" align="right" valign="top"><a class="el" href="../../db/d84/malloc__dbg_8c.html#ab6619fb17769f2e4e2e36c9ef2dda3c6">mem_info</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d84/malloc__dbg_8c.html#afae235c0e32e4c8b7d67117da5f78946">addMemInfo</a> (<a class="el" href="../../db/d84/malloc__dbg_8c.html#ab6619fb17769f2e4e2e36c9ef2dda3c6">mem_info</a> *memoryInfo, void *ptrToReturn, size_t bytes, int line, const char *filename, const char *functionName)</td></tr>
|
||
|
<tr class="memdesc:afae235c0e32e4c8b7d67117da5f78946"><td class="mdescLeft"> </td><td class="mdescRight">addMemInfo function add a memory allocation in the memoryInfo list. <a href="../../db/d84/malloc__dbg_8c.html#afae235c0e32e4c8b7d67117da5f78946">More...</a><br /></td></tr>
|
||
|
<tr class="separator:afae235c0e32e4c8b7d67117da5f78946"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:acd08c54b257fb81e57f16c94690072f2"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d84/malloc__dbg_8c.html#acd08c54b257fb81e57f16c94690072f2">inList</a> (const char *filename, int line)</td></tr>
|
||
|
<tr class="memdesc:acd08c54b257fb81e57f16c94690072f2"><td class="mdescLeft"> </td><td class="mdescRight">inList function is used to know if an element is already in the memoryInfo list. <a href="../../db/d84/malloc__dbg_8c.html#acd08c54b257fb81e57f16c94690072f2">More...</a><br /></td></tr>
|
||
|
<tr class="separator:acd08c54b257fb81e57f16c94690072f2"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:a8ac3a93239838ac88c18df64c58b9275"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d84/malloc__dbg_8c.html#a8ac3a93239838ac88c18df64c58b9275">editInfo</a> (int elemPos, size_t bytes)</td></tr>
|
||
|
<tr class="memdesc:a8ac3a93239838ac88c18df64c58b9275"><td class="mdescLeft"> </td><td class="mdescRight">editInfo function is used to edit an element in the memoryInfo list. <a href="../../db/d84/malloc__dbg_8c.html#a8ac3a93239838ac88c18df64c58b9275">More...</a><br /></td></tr>
|
||
|
<tr class="separator:a8ac3a93239838ac88c18df64c58b9275"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:a10238aaeea60178d31fbb74347e941aa"><td class="memItemLeft" align="right" valign="top">void * </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d84/malloc__dbg_8c.html#a10238aaeea60178d31fbb74347e941aa">malloc_dbg</a> (size_t bytes, int line, const char *filename, const char *functionName)</td></tr>
|
||
|
<tr class="memdesc:a10238aaeea60178d31fbb74347e941aa"><td class="mdescLeft"> </td><td class="mdescRight">malloc_dbg function is a wrapper around the malloc function. <a href="../../db/d84/malloc__dbg_8c.html#a10238aaeea60178d31fbb74347e941aa">More...</a><br /></td></tr>
|
||
|
<tr class="separator:a10238aaeea60178d31fbb74347e941aa"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:aec6b5ee323e5338f23a1ce6fe9974f25"><td class="memItemLeft" align="right" valign="top">void * </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d84/malloc__dbg_8c.html#aec6b5ee323e5338f23a1ce6fe9974f25">calloc_dbg</a> (size_t elementCount, size_t elementSize, int line, const char *filename, const char *functionName)</td></tr>
|
||
|
<tr class="memdesc:aec6b5ee323e5338f23a1ce6fe9974f25"><td class="mdescLeft"> </td><td class="mdescRight">calloc_dbg function is a wrapper around the calloc function. <a href="../../db/d84/malloc__dbg_8c.html#aec6b5ee323e5338f23a1ce6fe9974f25">More...</a><br /></td></tr>
|
||
|
<tr class="separator:aec6b5ee323e5338f23a1ce6fe9974f25"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:a3f9195a04ac8e8a9868ee3e416db7e8c"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d84/malloc__dbg_8c.html#a3f9195a04ac8e8a9868ee3e416db7e8c">free_dbg</a> (void *ptrToFree)</td></tr>
|
||
|
<tr class="memdesc:a3f9195a04ac8e8a9868ee3e416db7e8c"><td class="mdescLeft"> </td><td class="mdescRight">free_dbg function is used to free the memory allocated to a pointer. <a href="../../db/d84/malloc__dbg_8c.html#a3f9195a04ac8e8a9868ee3e416db7e8c">More...</a><br /></td></tr>
|
||
|
<tr class="separator:a3f9195a04ac8e8a9868ee3e416db7e8c"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:a2a47e4c38db8c00b80248e5535adf797"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d84/malloc__dbg_8c.html#a2a47e4c38db8c00b80248e5535adf797">printLeaks</a> ()</td></tr>
|
||
|
<tr class="memdesc:a2a47e4c38db8c00b80248e5535adf797"><td class="mdescLeft"> </td><td class="mdescRight">printLeaks function is used to print all the memory leaks. <a href="../../db/d84/malloc__dbg_8c.html#a2a47e4c38db8c00b80248e5535adf797">More...</a><br /></td></tr>
|
||
|
<tr class="separator:a2a47e4c38db8c00b80248e5535adf797"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
</table><table class="memberdecls">
|
||
|
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="var-members"></a>
|
||
|
Variables</h2></td></tr>
|
||
|
<tr class="memitem:afebd751704cd878d2e4b88499519c6e3"><td class="memItemLeft" align="right" valign="top"><a id="afebd751704cd878d2e4b88499519c6e3"></a>
|
||
|
<a class="el" href="../../db/d84/malloc__dbg_8c.html#ab6619fb17769f2e4e2e36c9ef2dda3c6">mem_info</a> * </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a> = NULL</td></tr>
|
||
|
<tr class="memdesc:afebd751704cd878d2e4b88499519c6e3"><td class="mdescLeft"> </td><td class="mdescRight">We use a global variable for the list so we can use it at any time. <br /></td></tr>
|
||
|
<tr class="separator:afebd751704cd878d2e4b88499519c6e3"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
<tr class="memitem:ad04afbbcb9f0f10bc7628ec4f0d7c950"><td class="memItemLeft" align="right" valign="top">int </td><td class="memItemRight" valign="bottom"><a class="el" href="../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950">atexitCalled</a> = 0</td></tr>
|
||
|
<tr class="memdesc:ad04afbbcb9f0f10bc7628ec4f0d7c950"><td class="mdescLeft"> </td><td class="mdescRight">Another global variable. <a href="../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950">More...</a><br /></td></tr>
|
||
|
<tr class="separator:ad04afbbcb9f0f10bc7628ec4f0d7c950"><td class="memSeparator" colspan="2"> </td></tr>
|
||
|
</table>
|
||
|
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
|
||
|
<div class="textblock"><p>This file contains malloc_dbg, calloc_dbg, free_dbg and printLeaks implementations. </p>
|
||
|
<dl class="section author"><dt>Author</dt><dd><a href="https://github.com/tinouduart33">tinouduart33</a> </dd></dl>
|
||
|
</div><h2 class="groupheader">Typedef Documentation</h2>
|
||
|
<a id="ab6619fb17769f2e4e2e36c9ef2dda3c6"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#ab6619fb17769f2e4e2e36c9ef2dda3c6">◆ </a></span>mem_info</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">typedef struct <a class="el" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">MEMORY_INFORMATION</a> <a class="el" href="../../db/d84/malloc__dbg_8c.html#ab6619fb17769f2e4e2e36c9ef2dda3c6">mem_info</a></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>For the malloc, calloc and free functions. </p>
|
||
|
<p>For IO operations (printf). For the memcmp function. Header file which contains the prototypes of malloc_dbg, calloc_dbg and fre_dbg.</p>
|
||
|
<p>Structure used to save an allocated pointer </p>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
<h2 class="groupheader">Function Documentation</h2>
|
||
|
<a id="afae235c0e32e4c8b7d67117da5f78946"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#afae235c0e32e4c8b7d67117da5f78946">◆ </a></span>addMemInfo()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname"><a class="el" href="../../db/d84/malloc__dbg_8c.html#ab6619fb17769f2e4e2e36c9ef2dda3c6">mem_info</a>* addMemInfo </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype"><a class="el" href="../../db/d84/malloc__dbg_8c.html#ab6619fb17769f2e4e2e36c9ef2dda3c6">mem_info</a> * </td>
|
||
|
<td class="paramname"><em>memoryInfo</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">void * </td>
|
||
|
<td class="paramname"><em>ptrToReturn</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">size_t </td>
|
||
|
<td class="paramname"><em>bytes</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">int </td>
|
||
|
<td class="paramname"><em>line</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">const char * </td>
|
||
|
<td class="paramname"><em>filename</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">const char * </td>
|
||
|
<td class="paramname"><em>functionName</em> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>addMemInfo function add a memory allocation in the memoryInfo list. </p>
|
||
|
<p>This function creates a new element and add it on top of the list </p><dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">memoryInfo</td><td>Pointer to the doubly linked list used to store all of the allocations </td></tr>
|
||
|
<tr><td class="paramname">ptrToreturn</td><td>Pointer returned by malloc or calloc </td></tr>
|
||
|
<tr><td class="paramname">bytes</td><td>Size in bytes of the allocation </td></tr>
|
||
|
<tr><td class="paramname">line</td><td>Line where the allocation has been called </td></tr>
|
||
|
<tr><td class="paramname">filename</td><td>File where the allocation has been called </td></tr>
|
||
|
<tr><td class="paramname">functionName</td><td>Name of the function where the allocation has been called </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>mem_info pointer if it succeeds, NULL otherwise </dd></dl>
|
||
|
<div class="fragment"><div class="line"><a name="l00052"></a><span class="lineno"> 52</span> {</div>
|
||
|
<div class="line"><a name="l00053"></a><span class="lineno"> 53</span>  <a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">mem_info</a>* newMemInfo = (<a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">mem_info</a>*)<a class="code" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(<span class="keyword">sizeof</span>(<a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">mem_info</a>));</div>
|
||
|
<div class="line"><a name="l00054"></a><span class="lineno"> 54</span>  <span class="keywordflow">if</span> (!newMemInfo)</div>
|
||
|
<div class="line"><a name="l00055"></a><span class="lineno"> 55</span>  {</div>
|
||
|
<div class="line"><a name="l00056"></a><span class="lineno"> 56</span>  <span class="keywordflow">return</span> NULL;</div>
|
||
|
<div class="line"><a name="l00057"></a><span class="lineno"> 57</span>  }</div>
|
||
|
<div class="line"><a name="l00058"></a><span class="lineno"> 58</span>  </div>
|
||
|
<div class="line"><a name="l00059"></a><span class="lineno"> 59</span>  newMemInfo-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a6b0971c1415de6e0123b8d0d0a626fde">ptr</a> = ptrToReturn;</div>
|
||
|
<div class="line"><a name="l00060"></a><span class="lineno"> 60</span>  newMemInfo-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a7f42967fd6562d77ac03445ea6e36a3d">bytes</a> = bytes;</div>
|
||
|
<div class="line"><a name="l00061"></a><span class="lineno"> 61</span>  newMemInfo-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a731603550d2238abb179f2b572f20d99">line</a> = line;</div>
|
||
|
<div class="line"><a name="l00062"></a><span class="lineno"> 62</span>  newMemInfo-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a934ad84d159c35b24ff54f7eceb1c6be">fileName</a> = filename;</div>
|
||
|
<div class="line"><a name="l00063"></a><span class="lineno"> 63</span>  newMemInfo-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a1f13725b3de5ca6ab99b238b712cb417">functionName</a> = functionName;</div>
|
||
|
<div class="line"><a name="l00064"></a><span class="lineno"> 64</span>  newMemInfo-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#aa296b903d0e2ac54acaa7c305bae8007">next</a> = memoryInfo;</div>
|
||
|
<div class="line"><a name="l00065"></a><span class="lineno"> 65</span>  newMemInfo-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a1cec46413acf776e3ee2b0b9241490c3">previous</a> = NULL;</div>
|
||
|
<div class="line"><a name="l00066"></a><span class="lineno"> 66</span>  <span class="keywordflow">if</span> (<a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>)</div>
|
||
|
<div class="line"><a name="l00067"></a><span class="lineno"> 67</span>  <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a1cec46413acf776e3ee2b0b9241490c3">previous</a> = newMemInfo;</div>
|
||
|
<div class="line"><a name="l00068"></a><span class="lineno"> 68</span>  </div>
|
||
|
<div class="line"><a name="l00069"></a><span class="lineno"> 69</span>  <span class="keywordflow">return</span> newMemInfo;</div>
|
||
|
<div class="line"><a name="l00070"></a><span class="lineno"> 70</span> }</div>
|
||
|
<div class="ttc" id="amalloc__dbg_8c_html_afebd751704cd878d2e4b88499519c6e3"><div class="ttname"><a href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a></div><div class="ttdeci">mem_info * memoryInformation</div><div class="ttdoc">We use a global variable for the list so we can use it at any time.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:33</div></div>
|
||
|
<div class="ttc" id="amalloc__dbg_8h_html_a725f50ecaf1959d96de79b36b4788fee"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a></div><div class="ttdeci">#define malloc(bytes)</div><div class="ttdoc">This macro replace the standard malloc function with malloc_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:18</div></div>
|
||
|
<div class="ttc" id="astruct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n_html"><div class="ttname"><a href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">MEMORY_INFORMATION</a></div><div class="ttdoc">For the malloc, calloc and free functions.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:21</div></div>
|
||
|
<div class="ttc" id="astruct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n_html_a1cec46413acf776e3ee2b0b9241490c3"><div class="ttname"><a href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a1cec46413acf776e3ee2b0b9241490c3">MEMORY_INFORMATION::previous</a></div><div class="ttdeci">struct MEMORY_INFORMATION * previous</div><div class="ttdoc">Previous element in the list.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:28</div></div>
|
||
|
<div class="ttc" id="astruct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n_html_a1f13725b3de5ca6ab99b238b712cb417"><div class="ttname"><a href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a1f13725b3de5ca6ab99b238b712cb417">MEMORY_INFORMATION::functionName</a></div><div class="ttdeci">const char * functionName</div><div class="ttdoc">Function in which malloc or calloc has been called.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:24</div></div>
|
||
|
<div class="ttc" id="astruct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n_html_a6b0971c1415de6e0123b8d0d0a626fde"><div class="ttname"><a href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a6b0971c1415de6e0123b8d0d0a626fde">MEMORY_INFORMATION::ptr</a></div><div class="ttdeci">void * ptr</div><div class="ttdoc">Pointer returned by malloc / calloc.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:22</div></div>
|
||
|
<div class="ttc" id="astruct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n_html_a731603550d2238abb179f2b572f20d99"><div class="ttname"><a href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a731603550d2238abb179f2b572f20d99">MEMORY_INFORMATION::line</a></div><div class="ttdeci">int line</div><div class="ttdoc">Line number (in file) corresponding to the malloc / calloc call.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:26</div></div>
|
||
|
<div class="ttc" id="astruct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n_html_a7f42967fd6562d77ac03445ea6e36a3d"><div class="ttname"><a href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a7f42967fd6562d77ac03445ea6e36a3d">MEMORY_INFORMATION::bytes</a></div><div class="ttdeci">size_t bytes</div><div class="ttdoc">Number of bytes allocated.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:25</div></div>
|
||
|
<div class="ttc" id="astruct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n_html_a934ad84d159c35b24ff54f7eceb1c6be"><div class="ttname"><a href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a934ad84d159c35b24ff54f7eceb1c6be">MEMORY_INFORMATION::fileName</a></div><div class="ttdeci">const char * fileName</div><div class="ttdoc">File in which malloc or calloc has been called.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:23</div></div>
|
||
|
<div class="ttc" id="astruct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n_html_aa296b903d0e2ac54acaa7c305bae8007"><div class="ttname"><a href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#aa296b903d0e2ac54acaa7c305bae8007">MEMORY_INFORMATION::next</a></div><div class="ttdeci">struct MEMORY_INFORMATION * next</div><div class="ttdoc">Next element in the list.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:27</div></div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="aec6b5ee323e5338f23a1ce6fe9974f25"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#aec6b5ee323e5338f23a1ce6fe9974f25">◆ </a></span>calloc_dbg()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">void* calloc_dbg </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype">size_t </td>
|
||
|
<td class="paramname"><em>elementCount</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">size_t </td>
|
||
|
<td class="paramname"><em>elementSize</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">int </td>
|
||
|
<td class="paramname"><em>line</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">const char * </td>
|
||
|
<td class="paramname"><em>filename</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">const char * </td>
|
||
|
<td class="paramname"><em>functionName</em> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>calloc_dbg function is a wrapper around the calloc function. </p>
|
||
|
<p>This function calls calloc and allocates the number of bytes passed in the parameters. If the allocation succeeds then it add the pointer returned by malloc in the mem_info list. </p><dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">elementCount</td><td>number of element to allocate </td></tr>
|
||
|
<tr><td class="paramname">elementSize</td><td>Size of each element </td></tr>
|
||
|
<tr><td class="paramname">line</td><td>Line number in the caller file </td></tr>
|
||
|
<tr><td class="paramname">filename</td><td>Caller file </td></tr>
|
||
|
<tr><td class="paramname">functionName</td><td>Caller function </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>Pointer returned by calloc if it's valid, NULL otherwhise. </dd></dl>
|
||
|
<div class="fragment"><div class="line"><a name="l00175"></a><span class="lineno"> 175</span> {</div>
|
||
|
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span>  <span class="keywordtype">void</span>* ptrToReturn = <a class="code" href="../../d2/ddd/malloc__dbg_8h.html#afdddaa949a93c1ef559a638e98f9c21b">calloc</a>(elementCount, elementSize);</div>
|
||
|
<div class="line"><a name="l00177"></a><span class="lineno"> 177</span>  <span class="keywordflow">if</span> (!ptrToReturn)</div>
|
||
|
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span>  {</div>
|
||
|
<div class="line"><a name="l00179"></a><span class="lineno"> 179</span>  <span class="keywordflow">return</span> NULL;</div>
|
||
|
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>  }</div>
|
||
|
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>  </div>
|
||
|
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>  <span class="comment">// We must check atexitCalled value to know if we already called the function</span></div>
|
||
|
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>  <span class="keywordflow">if</span> (!<a class="code" href="../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950">atexitCalled</a>)</div>
|
||
|
<div class="line"><a name="l00184"></a><span class="lineno"> 184</span>  {</div>
|
||
|
<div class="line"><a name="l00185"></a><span class="lineno"> 185</span>  atexit(<a class="code" href="../../db/d84/malloc__dbg_8c.html#a2a47e4c38db8c00b80248e5535adf797">printLeaks</a>); <span class="comment">// Used to call printLeaks when the program exit</span></div>
|
||
|
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>  <a class="code" href="../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950">atexitCalled</a> = 1;</div>
|
||
|
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>  }</div>
|
||
|
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>  </div>
|
||
|
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>  <span class="comment">// Add a new element in the mem_info list</span></div>
|
||
|
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>  <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a> = <a class="code" href="../../db/d84/malloc__dbg_8c.html#afae235c0e32e4c8b7d67117da5f78946">addMemInfo</a>(<a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>, ptrToReturn, elementCount * elementSize, line, filename, functionName);</div>
|
||
|
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>  <span class="keywordflow">if</span> (!<a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>)</div>
|
||
|
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>  {</div>
|
||
|
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span>  <a class="code" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(ptrToReturn);</div>
|
||
|
<div class="line"><a name="l00194"></a><span class="lineno"> 194</span>  <span class="keywordflow">return</span> NULL;</div>
|
||
|
<div class="line"><a name="l00195"></a><span class="lineno"> 195</span>  }</div>
|
||
|
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span>  </div>
|
||
|
<div class="line"><a name="l00197"></a><span class="lineno"> 197</span>  <span class="keywordflow">return</span> ptrToReturn;</div>
|
||
|
<div class="line"><a name="l00198"></a><span class="lineno"> 198</span> }</div>
|
||
|
<div class="ttc" id="amalloc__dbg_8c_html_a2a47e4c38db8c00b80248e5535adf797"><div class="ttname"><a href="../../db/d84/malloc__dbg_8c.html#a2a47e4c38db8c00b80248e5535adf797">printLeaks</a></div><div class="ttdeci">void printLeaks()</div><div class="ttdoc">printLeaks function is used to print all the memory leaks.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:264</div></div>
|
||
|
<div class="ttc" id="amalloc__dbg_8c_html_ad04afbbcb9f0f10bc7628ec4f0d7c950"><div class="ttname"><a href="../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950">atexitCalled</a></div><div class="ttdeci">int atexitCalled</div><div class="ttdoc">Another global variable.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:37</div></div>
|
||
|
<div class="ttc" id="amalloc__dbg_8c_html_afae235c0e32e4c8b7d67117da5f78946"><div class="ttname"><a href="../../db/d84/malloc__dbg_8c.html#afae235c0e32e4c8b7d67117da5f78946">addMemInfo</a></div><div class="ttdeci">mem_info * addMemInfo(mem_info *memoryInfo, void *ptrToReturn, size_t bytes, int line, const char *filename, const char *functionName)</div><div class="ttdoc">addMemInfo function add a memory allocation in the memoryInfo list.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:51</div></div>
|
||
|
<div class="ttc" id="amalloc__dbg_8h_html_a9cc854374299a1dd933bf62029761768"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a></div><div class="ttdeci">#define free(ptr)</div><div class="ttdoc">This macro replace the standard free function with free_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:26</div></div>
|
||
|
<div class="ttc" id="amalloc__dbg_8h_html_afdddaa949a93c1ef559a638e98f9c21b"><div class="ttname"><a href="../../d2/ddd/malloc__dbg_8h.html#afdddaa949a93c1ef559a638e98f9c21b">calloc</a></div><div class="ttdeci">#define calloc(elemCount, elemSize)</div><div class="ttdoc">This macro replace the standard calloc function with calloc_dbg.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.h:22</div></div>
|
||
|
</div><!-- fragment --><div class="dynheader">
|
||
|
Here is the call graph for this function:</div>
|
||
|
<div class="dyncontent">
|
||
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../db/d84/malloc__dbg_8c_aec6b5ee323e5338f23a1ce6fe9974f25_cgraph.svg" width="238" height="88"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="a8ac3a93239838ac88c18df64c58b9275"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#a8ac3a93239838ac88c18df64c58b9275">◆ </a></span>editInfo()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">void editInfo </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype">int </td>
|
||
|
<td class="paramname"><em>elemPos</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">size_t </td>
|
||
|
<td class="paramname"><em>bytes</em> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>editInfo function is used to edit an element in the memoryInfo list. </p>
|
||
|
<p>This function is used to edit the number of bytes allocated at a specific line. </p><dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">elemPos</td><td>Position of an element in the doubly linked list memoryInfo </td></tr>
|
||
|
<tr><td class="paramname">bytes</td><td>Size of the allocation in bytes </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>Nothing. </dd></dl>
|
||
|
<div class="fragment"><div class="line"><a name="l00108"></a><span class="lineno"> 108</span> {</div>
|
||
|
<div class="line"><a name="l00109"></a><span class="lineno"> 109</span>  <span class="keywordtype">int</span> counter = 0;</div>
|
||
|
<div class="line"><a name="l00110"></a><span class="lineno"> 110</span>  <a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">mem_info</a>* tmp = <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>;</div>
|
||
|
<div class="line"><a name="l00111"></a><span class="lineno"> 111</span>  </div>
|
||
|
<div class="line"><a name="l00112"></a><span class="lineno"> 112</span>  <span class="keywordflow">while</span> (counter != elemPos)</div>
|
||
|
<div class="line"><a name="l00113"></a><span class="lineno"> 113</span>  {</div>
|
||
|
<div class="line"><a name="l00114"></a><span class="lineno"> 114</span>  tmp = tmp->next;</div>
|
||
|
<div class="line"><a name="l00115"></a><span class="lineno"> 115</span>  counter++;</div>
|
||
|
<div class="line"><a name="l00116"></a><span class="lineno"> 116</span>  }</div>
|
||
|
<div class="line"><a name="l00117"></a><span class="lineno"> 117</span>  tmp->bytes += bytes;</div>
|
||
|
<div class="line"><a name="l00118"></a><span class="lineno"> 118</span> }</div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="a3f9195a04ac8e8a9868ee3e416db7e8c"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#a3f9195a04ac8e8a9868ee3e416db7e8c">◆ </a></span>free_dbg()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">void free_dbg </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype">void * </td>
|
||
|
<td class="paramname"><em>ptrToFree</em></td><td>)</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>free_dbg function is used to free the memory allocated to a pointer. </p>
|
||
|
<p>This function free the memory pointed by the pointer passed in parameter. To free this pointer, we loop through the mem_info list and check if we find the pointer. Once it's found, the pointer is freed and the element is deleted from the list. </p><dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">ptrToFree</td><td>Pointer that must be freed </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>Nothing. </dd></dl>
|
||
|
<div class="fragment"><div class="line"><a name="l00209"></a><span class="lineno"> 209</span> {</div>
|
||
|
<div class="line"><a name="l00210"></a><span class="lineno"> 210</span>  <a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">mem_info</a>* tmp = <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>;</div>
|
||
|
<div class="line"><a name="l00211"></a><span class="lineno"> 211</span>  <a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">mem_info</a>* toFree = NULL;</div>
|
||
|
<div class="line"><a name="l00212"></a><span class="lineno"> 212</span>  <a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">mem_info</a>* previous = NULL;</div>
|
||
|
<div class="line"><a name="l00213"></a><span class="lineno"> 213</span>  </div>
|
||
|
<div class="line"><a name="l00214"></a><span class="lineno"> 214</span>  <span class="comment">// Check if the head contains the pointer to free</span></div>
|
||
|
<div class="line"><a name="l00215"></a><span class="lineno"> 215</span>  <span class="keywordflow">if</span> (tmp->ptr == ptrToFree)</div>
|
||
|
<div class="line"><a name="l00216"></a><span class="lineno"> 216</span>  {</div>
|
||
|
<div class="line"><a name="l00217"></a><span class="lineno"> 217</span>  toFree = tmp;</div>
|
||
|
<div class="line"><a name="l00218"></a><span class="lineno"> 218</span>  <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a> = tmp->next;</div>
|
||
|
<div class="line"><a name="l00219"></a><span class="lineno"> 219</span>  <a class="code" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(toFree-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a6b0971c1415de6e0123b8d0d0a626fde">ptr</a>);</div>
|
||
|
<div class="line"><a name="l00220"></a><span class="lineno"> 220</span>  <a class="code" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(toFree);</div>
|
||
|
<div class="line"><a name="l00221"></a><span class="lineno"> 221</span>  <span class="keywordflow">if</span> (<a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>)</div>
|
||
|
<div class="line"><a name="l00222"></a><span class="lineno"> 222</span>  {</div>
|
||
|
<div class="line"><a name="l00223"></a><span class="lineno"> 223</span>  <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a1cec46413acf776e3ee2b0b9241490c3">previous</a> = NULL;</div>
|
||
|
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>  }</div>
|
||
|
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>  <span class="keywordflow">return</span>;</div>
|
||
|
<div class="line"><a name="l00226"></a><span class="lineno"> 226</span>  }</div>
|
||
|
<div class="line"><a name="l00227"></a><span class="lineno"> 227</span>  </div>
|
||
|
<div class="line"><a name="l00228"></a><span class="lineno"> 228</span>  <span class="comment">// We can loop through the list without any problems, the head is not the pointer</span></div>
|
||
|
<div class="line"><a name="l00229"></a><span class="lineno"> 229</span>  <span class="keywordflow">while</span> (tmp)</div>
|
||
|
<div class="line"><a name="l00230"></a><span class="lineno"> 230</span>  {</div>
|
||
|
<div class="line"><a name="l00231"></a><span class="lineno"> 231</span>  <span class="keywordflow">if</span> (tmp->ptr == ptrToFree) <span class="comment">// If we found the pointer that must be freed</span></div>
|
||
|
<div class="line"><a name="l00232"></a><span class="lineno"> 232</span>  {</div>
|
||
|
<div class="line"><a name="l00233"></a><span class="lineno"> 233</span>  toFree = tmp;</div>
|
||
|
<div class="line"><a name="l00234"></a><span class="lineno"> 234</span>  tmp = tmp->next;</div>
|
||
|
<div class="line"><a name="l00235"></a><span class="lineno"> 235</span>  previous = toFree-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a1cec46413acf776e3ee2b0b9241490c3">previous</a>;</div>
|
||
|
<div class="line"><a name="l00236"></a><span class="lineno"> 236</span>  </div>
|
||
|
<div class="line"><a name="l00237"></a><span class="lineno"> 237</span>  <span class="keywordflow">if</span> (previous)</div>
|
||
|
<div class="line"><a name="l00238"></a><span class="lineno"> 238</span>  {</div>
|
||
|
<div class="line"><a name="l00239"></a><span class="lineno"> 239</span>  previous-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#aa296b903d0e2ac54acaa7c305bae8007">next</a> = tmp;</div>
|
||
|
<div class="line"><a name="l00240"></a><span class="lineno"> 240</span>  }</div>
|
||
|
<div class="line"><a name="l00241"></a><span class="lineno"> 241</span>  <span class="keywordflow">if</span> (tmp)</div>
|
||
|
<div class="line"><a name="l00242"></a><span class="lineno"> 242</span>  {</div>
|
||
|
<div class="line"><a name="l00243"></a><span class="lineno"> 243</span>  tmp->previous = previous;</div>
|
||
|
<div class="line"><a name="l00244"></a><span class="lineno"> 244</span>  }</div>
|
||
|
<div class="line"><a name="l00245"></a><span class="lineno"> 245</span>  </div>
|
||
|
<div class="line"><a name="l00246"></a><span class="lineno"> 246</span>  <a class="code" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(toFree-><a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html#a6b0971c1415de6e0123b8d0d0a626fde">ptr</a>);</div>
|
||
|
<div class="line"><a name="l00247"></a><span class="lineno"> 247</span>  <span class="keywordflow">if</span> (toFree == <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>)</div>
|
||
|
<div class="line"><a name="l00248"></a><span class="lineno"> 248</span>  {</div>
|
||
|
<div class="line"><a name="l00249"></a><span class="lineno"> 249</span>  <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a> = NULL;</div>
|
||
|
<div class="line"><a name="l00250"></a><span class="lineno"> 250</span>  }</div>
|
||
|
<div class="line"><a name="l00251"></a><span class="lineno"> 251</span>  <a class="code" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(toFree);</div>
|
||
|
<div class="line"><a name="l00252"></a><span class="lineno"> 252</span>  <span class="keywordflow">return</span>;</div>
|
||
|
<div class="line"><a name="l00253"></a><span class="lineno"> 253</span>  }</div>
|
||
|
<div class="line"><a name="l00254"></a><span class="lineno"> 254</span>  tmp = tmp->next;</div>
|
||
|
<div class="line"><a name="l00255"></a><span class="lineno"> 255</span>  }</div>
|
||
|
<div class="line"><a name="l00256"></a><span class="lineno"> 256</span> }</div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="acd08c54b257fb81e57f16c94690072f2"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#acd08c54b257fb81e57f16c94690072f2">◆ </a></span>inList()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">int inList </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype">const char * </td>
|
||
|
<td class="paramname"><em>filename</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">int </td>
|
||
|
<td class="paramname"><em>line</em> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>inList function is used to know if an element is already in the memoryInfo list. </p>
|
||
|
<p>This function is used to know if an allocation in a specific file at a specific line already exists in the list. </p><dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">filename</td><td>File in which malloc or calloc has been called </td></tr>
|
||
|
<tr><td class="paramname">line</td><td>Line number in the file in which malloc or calloc has been called </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>Position of the element in the list if the element is found, -1 otherwise. </dd></dl>
|
||
|
<div class="fragment"><div class="line"><a name="l00080"></a><span class="lineno"> 80</span> {</div>
|
||
|
<div class="line"><a name="l00081"></a><span class="lineno"> 81</span>  <a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">mem_info</a>* tmp = <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>;</div>
|
||
|
<div class="line"><a name="l00082"></a><span class="lineno"> 82</span>  <span class="keywordtype">int</span> counter = 0;</div>
|
||
|
<div class="line"><a name="l00083"></a><span class="lineno"> 83</span>  <span class="keywordtype">int</span> len = strlen(filename);</div>
|
||
|
<div class="line"><a name="l00084"></a><span class="lineno"> 84</span>  </div>
|
||
|
<div class="line"><a name="l00085"></a><span class="lineno"> 85</span>  <span class="keywordflow">while</span> (tmp)</div>
|
||
|
<div class="line"><a name="l00086"></a><span class="lineno"> 86</span>  {</div>
|
||
|
<div class="line"><a name="l00087"></a><span class="lineno"> 87</span>  <span class="keywordflow">if</span> (len == strlen(tmp->fileName))</div>
|
||
|
<div class="line"><a name="l00088"></a><span class="lineno"> 88</span>  {</div>
|
||
|
<div class="line"><a name="l00089"></a><span class="lineno"> 89</span>  <span class="keywordflow">if</span> (!memcmp(filename, tmp->fileName, len) && tmp->line == line)</div>
|
||
|
<div class="line"><a name="l00090"></a><span class="lineno"> 90</span>  {</div>
|
||
|
<div class="line"><a name="l00091"></a><span class="lineno"> 91</span>  <span class="keywordflow">return</span> counter;</div>
|
||
|
<div class="line"><a name="l00092"></a><span class="lineno"> 92</span>  }</div>
|
||
|
<div class="line"><a name="l00093"></a><span class="lineno"> 93</span>  }</div>
|
||
|
<div class="line"><a name="l00094"></a><span class="lineno"> 94</span>  tmp = tmp->next;</div>
|
||
|
<div class="line"><a name="l00095"></a><span class="lineno"> 95</span>  counter++;</div>
|
||
|
<div class="line"><a name="l00096"></a><span class="lineno"> 96</span>  }</div>
|
||
|
<div class="line"><a name="l00097"></a><span class="lineno"> 97</span>  <span class="keywordflow">return</span> -1;</div>
|
||
|
<div class="line"><a name="l00098"></a><span class="lineno"> 98</span> }</div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="a10238aaeea60178d31fbb74347e941aa"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#a10238aaeea60178d31fbb74347e941aa">◆ </a></span>malloc_dbg()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">void* malloc_dbg </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype">size_t </td>
|
||
|
<td class="paramname"><em>bytes</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">int </td>
|
||
|
<td class="paramname"><em>line</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">const char * </td>
|
||
|
<td class="paramname"><em>filename</em>, </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td class="paramkey"></td>
|
||
|
<td></td>
|
||
|
<td class="paramtype">const char * </td>
|
||
|
<td class="paramname"><em>functionName</em> </td>
|
||
|
</tr>
|
||
|
<tr>
|
||
|
<td></td>
|
||
|
<td>)</td>
|
||
|
<td></td><td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>malloc_dbg function is a wrapper around the malloc function. </p>
|
||
|
<p>This function calls malloc and allocates the number of bytes passed in the parameters. If the allocation succeeds then it add the pointer returned by malloc in the mem_info list. </p><dl class="params"><dt>Parameters</dt><dd>
|
||
|
<table class="params">
|
||
|
<tr><td class="paramname">bytes</td><td>Size of the allocation in bytes </td></tr>
|
||
|
<tr><td class="paramname">filename</td><td>Caller file </td></tr>
|
||
|
<tr><td class="paramname">functionName</td><td>Caller function </td></tr>
|
||
|
</table>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
<dl class="section return"><dt>Returns</dt><dd>Pointer returned by malloc if it's valid, NULL otherwhise. </dd></dl>
|
||
|
<div class="fragment"><div class="line"><a name="l00130"></a><span class="lineno"> 130</span> {</div>
|
||
|
<div class="line"><a name="l00131"></a><span class="lineno"> 131</span>  <span class="keywordtype">void</span>* ptrToReturn = <a class="code" href="../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee">malloc</a>(bytes);</div>
|
||
|
<div class="line"><a name="l00132"></a><span class="lineno"> 132</span>  <span class="keywordtype">int</span> pos = 0;</div>
|
||
|
<div class="line"><a name="l00133"></a><span class="lineno"> 133</span>  <span class="keywordflow">if</span> (!ptrToReturn)</div>
|
||
|
<div class="line"><a name="l00134"></a><span class="lineno"> 134</span>  {</div>
|
||
|
<div class="line"><a name="l00135"></a><span class="lineno"> 135</span>  <span class="keywordflow">return</span> NULL;</div>
|
||
|
<div class="line"><a name="l00136"></a><span class="lineno"> 136</span>  }</div>
|
||
|
<div class="line"><a name="l00137"></a><span class="lineno"> 137</span>  </div>
|
||
|
<div class="line"><a name="l00138"></a><span class="lineno"> 138</span>  <span class="comment">// We must check atexitCalled value to know if we already called the function</span></div>
|
||
|
<div class="line"><a name="l00139"></a><span class="lineno"> 139</span>  <span class="keywordflow">if</span> (!<a class="code" href="../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950">atexitCalled</a>)</div>
|
||
|
<div class="line"><a name="l00140"></a><span class="lineno"> 140</span>  {</div>
|
||
|
<div class="line"><a name="l00141"></a><span class="lineno"> 141</span>  atexit(<a class="code" href="../../db/d84/malloc__dbg_8c.html#a2a47e4c38db8c00b80248e5535adf797">printLeaks</a>); <span class="comment">// Used to call printLeaks when the program exit</span></div>
|
||
|
<div class="line"><a name="l00142"></a><span class="lineno"> 142</span>  <a class="code" href="../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950">atexitCalled</a> = 1;</div>
|
||
|
<div class="line"><a name="l00143"></a><span class="lineno"> 143</span>  }</div>
|
||
|
<div class="line"><a name="l00144"></a><span class="lineno"> 144</span>  </div>
|
||
|
<div class="line"><a name="l00145"></a><span class="lineno"> 145</span>  pos = <a class="code" href="../../db/d84/malloc__dbg_8c.html#acd08c54b257fb81e57f16c94690072f2">inList</a>(filename, line);</div>
|
||
|
<div class="line"><a name="l00146"></a><span class="lineno"> 146</span>  <span class="keywordflow">if</span> (pos == -1)</div>
|
||
|
<div class="line"><a name="l00147"></a><span class="lineno"> 147</span>  {</div>
|
||
|
<div class="line"><a name="l00148"></a><span class="lineno"> 148</span>  <span class="comment">// Add a new element in the mem_info list</span></div>
|
||
|
<div class="line"><a name="l00149"></a><span class="lineno"> 149</span>  <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a> = <a class="code" href="../../db/d84/malloc__dbg_8c.html#afae235c0e32e4c8b7d67117da5f78946">addMemInfo</a>(<a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>, ptrToReturn, bytes, line, filename, functionName);</div>
|
||
|
<div class="line"><a name="l00150"></a><span class="lineno"> 150</span>  <span class="keywordflow">if</span> (!<a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>)</div>
|
||
|
<div class="line"><a name="l00151"></a><span class="lineno"> 151</span>  {</div>
|
||
|
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span>  <a class="code" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(ptrToReturn);</div>
|
||
|
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span>  <span class="keywordflow">return</span> NULL;</div>
|
||
|
<div class="line"><a name="l00154"></a><span class="lineno"> 154</span>  }</div>
|
||
|
<div class="line"><a name="l00155"></a><span class="lineno"> 155</span>  }</div>
|
||
|
<div class="line"><a name="l00156"></a><span class="lineno"> 156</span>  <span class="keywordflow">else</span></div>
|
||
|
<div class="line"><a name="l00157"></a><span class="lineno"> 157</span>  {</div>
|
||
|
<div class="line"><a name="l00158"></a><span class="lineno"> 158</span>  <a class="code" href="../../db/d84/malloc__dbg_8c.html#a8ac3a93239838ac88c18df64c58b9275">editInfo</a>(pos, bytes);</div>
|
||
|
<div class="line"><a name="l00159"></a><span class="lineno"> 159</span>  }</div>
|
||
|
<div class="line"><a name="l00160"></a><span class="lineno"> 160</span>  <span class="keywordflow">return</span> ptrToReturn;</div>
|
||
|
<div class="line"><a name="l00161"></a><span class="lineno"> 161</span> }</div>
|
||
|
<div class="ttc" id="amalloc__dbg_8c_html_a8ac3a93239838ac88c18df64c58b9275"><div class="ttname"><a href="../../db/d84/malloc__dbg_8c.html#a8ac3a93239838ac88c18df64c58b9275">editInfo</a></div><div class="ttdeci">void editInfo(int elemPos, size_t bytes)</div><div class="ttdoc">editInfo function is used to edit an element in the memoryInfo list.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:107</div></div>
|
||
|
<div class="ttc" id="amalloc__dbg_8c_html_acd08c54b257fb81e57f16c94690072f2"><div class="ttname"><a href="../../db/d84/malloc__dbg_8c.html#acd08c54b257fb81e57f16c94690072f2">inList</a></div><div class="ttdeci">int inList(const char *filename, int line)</div><div class="ttdoc">inList function is used to know if an element is already in the memoryInfo list.</div><div class="ttdef"><b>Definition:</b> malloc_dbg.c:79</div></div>
|
||
|
</div><!-- fragment --><div class="dynheader">
|
||
|
Here is the call graph for this function:</div>
|
||
|
<div class="dyncontent">
|
||
|
<div class="center"><iframe scrolling="no" frameborder="0" src="../../db/d84/malloc__dbg_8c_a10238aaeea60178d31fbb74347e941aa_cgraph.svg" width="242" height="190"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
<a id="a2a47e4c38db8c00b80248e5535adf797"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#a2a47e4c38db8c00b80248e5535adf797">◆ </a></span>printLeaks()</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">void printLeaks </td>
|
||
|
<td>(</td>
|
||
|
<td class="paramtype">void </td>
|
||
|
<td class="paramname"></td><td>)</td>
|
||
|
<td></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>printLeaks function is used to print all the memory leaks. </p>
|
||
|
<p>This function is called when the program exits. It loop through the mem_info list and if it's not empty, it prints the memory leaks. </p><dl class="section return"><dt>Returns</dt><dd>Nothing. </dd></dl>
|
||
|
<div class="fragment"><div class="line"><a name="l00265"></a><span class="lineno"> 265</span> {</div>
|
||
|
<div class="line"><a name="l00266"></a><span class="lineno"> 266</span>  <a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">mem_info</a>* tmp = <a class="code" href="../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3">memoryInformation</a>;</div>
|
||
|
<div class="line"><a name="l00267"></a><span class="lineno"> 267</span>  <a class="code" href="../../d4/d73/struct_m_e_m_o_r_y___i_n_f_o_r_m_a_t_i_o_n.html">mem_info</a>* previous = NULL;</div>
|
||
|
<div class="line"><a name="l00268"></a><span class="lineno"> 268</span>  <span class="keywordtype">size_t</span> sum = 0;</div>
|
||
|
<div class="line"><a name="l00269"></a><span class="lineno"> 269</span>  <span class="keywordtype">int</span> nbBlocks = 0;</div>
|
||
|
<div class="line"><a name="l00270"></a><span class="lineno"> 270</span>  </div>
|
||
|
<div class="line"><a name="l00271"></a><span class="lineno"> 271</span>  <span class="keywordflow">if</span> (tmp)</div>
|
||
|
<div class="line"><a name="l00272"></a><span class="lineno"> 272</span>  {</div>
|
||
|
<div class="line"><a name="l00273"></a><span class="lineno"> 273</span>  printf(<span class="stringliteral">"Memory Leaks detected.\n"</span>);</div>
|
||
|
<div class="line"><a name="l00274"></a><span class="lineno"> 274</span>  }</div>
|
||
|
<div class="line"><a name="l00275"></a><span class="lineno"> 275</span>  </div>
|
||
|
<div class="line"><a name="l00276"></a><span class="lineno"> 276</span>  <span class="keywordflow">while</span> (tmp)</div>
|
||
|
<div class="line"><a name="l00277"></a><span class="lineno"> 277</span>  {</div>
|
||
|
<div class="line"><a name="l00278"></a><span class="lineno"> 278</span>  previous = tmp;</div>
|
||
|
<div class="line"><a name="l00279"></a><span class="lineno"> 279</span>  printf(<span class="stringliteral">"\n%ld bytes lost\n"</span>, tmp->bytes);</div>
|
||
|
<div class="line"><a name="l00280"></a><span class="lineno"> 280</span>  printf(<span class="stringliteral">"address : 0x%p in %s\t%s:%d\n"</span>, tmp->ptr, tmp->functionName, tmp->fileName, tmp->line);</div>
|
||
|
<div class="line"><a name="l00281"></a><span class="lineno"> 281</span>  printf(<span class="stringliteral">"\n====================================\n"</span>);</div>
|
||
|
<div class="line"><a name="l00282"></a><span class="lineno"> 282</span>  sum += tmp->bytes;</div>
|
||
|
<div class="line"><a name="l00283"></a><span class="lineno"> 283</span>  tmp = tmp->next;</div>
|
||
|
<div class="line"><a name="l00284"></a><span class="lineno"> 284</span>  <a class="code" href="../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768">free</a>(previous);</div>
|
||
|
<div class="line"><a name="l00285"></a><span class="lineno"> 285</span>  nbBlocks++;</div>
|
||
|
<div class="line"><a name="l00286"></a><span class="lineno"> 286</span>  }</div>
|
||
|
<div class="line"><a name="l00287"></a><span class="lineno"> 287</span>  </div>
|
||
|
<div class="line"><a name="l00288"></a><span class="lineno"> 288</span>  printf(<span class="stringliteral">"SUMMARY :\n%ld bytes lost in %d blocks\n"</span>, sum, nbBlocks);</div>
|
||
|
<div class="line"><a name="l00289"></a><span class="lineno"> 289</span> }</div>
|
||
|
</div><!-- fragment -->
|
||
|
</div>
|
||
|
</div>
|
||
|
<h2 class="groupheader">Variable Documentation</h2>
|
||
|
<a id="ad04afbbcb9f0f10bc7628ec4f0d7c950"></a>
|
||
|
<h2 class="memtitle"><span class="permalink"><a href="#ad04afbbcb9f0f10bc7628ec4f0d7c950">◆ </a></span>atexitCalled</h2>
|
||
|
|
||
|
<div class="memitem">
|
||
|
<div class="memproto">
|
||
|
<table class="memname">
|
||
|
<tr>
|
||
|
<td class="memname">int atexitCalled = 0</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div><div class="memdoc">
|
||
|
|
||
|
<p>Another global variable. </p>
|
||
|
<p>This one is used to know if we already call the atexit function. </p>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div><!-- contents -->
|
||
|
</div><!-- doc-content -->
|
||
|
<!-- start footer part -->
|
||
|
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
|
||
|
<ul>
|
||
|
<li class="navelem"><a class="el" href="../../dir_abf1a26ece768c4076e73592705ae077.html">developer_tools</a></li><li class="navelem"><a class="el" href="../../db/d84/malloc__dbg_8c.html">malloc_dbg.c</a></li>
|
||
|
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|