2021-02-18 06:41:16 +08:00
<!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" / >
2021-10-26 03:34:27 +08:00
< meta http-equiv = "X-UA-Compatible" content = "IE=11" / >
< meta name = "generator" content = "Doxygen 1.9.2" / >
2021-02-18 06:41:16 +08:00
< 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" >
2021-10-26 03:34:27 +08:00
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
2021-02-18 06:41:16 +08:00
});
< / 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;" >
2021-10-26 03:34:27 +08:00
< div id = "projectname" > Algorithms_in_C< span id = "projectnumber" >   1.0.0< / span >
2021-02-18 06:41:16 +08:00
< / div >
< div id = "projectbrief" > Set of algorithms implemented in C.< / div >
< / td >
< / tr >
< / tbody >
< / table >
< / div >
<!-- end header part -->
2021-10-26 03:34:27 +08:00
<!-- Generated by Doxygen 1.9.2 -->
2021-02-18 06:41:16 +08:00
< script type = "text/javascript" >
2021-10-26 03:34:27 +08:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search",'Search','.html');
2021-02-18 06:41:16 +08:00
/* @license-end */
< / script >
< script type = "text/javascript" src = "../../menudata.js" > < / script >
< script type = "text/javascript" src = "../../menu.js" > < / script >
< script type = "text/javascript" >
2021-10-26 03:34:27 +08:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
2021-02-18 06:41:16 +08:00
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
2021-10-26 03:34:27 +08:00
/* @license-end */
< / script >
2021-02-18 06:41:16 +08:00
< 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" >
2021-10-26 03:34:27 +08:00
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699& dn=expat.txt MIT */
2021-02-18 06:41:16 +08:00
$(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 >
2021-10-26 03:34:27 +08:00
< div class = "headertitle" > < div class = "title" > malloc_dbg.c File Reference< / div > < / div >
2021-02-18 06:41:16 +08:00
< / 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" >
2021-10-26 03:34:27 +08:00
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../d7/d70/malloc__dbg_8c__incl.svg" width = "376" height = "127" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
2021-02-18 06:41:16 +08:00
< / div >
< / div >
< / div > < table class = "memberdecls" >
2021-10-26 03:34:27 +08:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "nested-classes" name = "nested-classes" > < / a >
2021-02-18 06:41:16 +08:00
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" >
2021-10-26 03:34:27 +08:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "typedef-members" name = "typedef-members" > < / a >
2021-02-18 06:41:16 +08:00
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" >
2021-10-26 03:34:27 +08:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "func-members" name = "func-members" > < / a >
2021-02-18 06:41:16 +08:00
Functions< / h2 > < / td > < / tr >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:a062aa89cafd39a97971a2eb22653ff2a" > < 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#a062aa89cafd39a97971a2eb22653ff2a" > 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:a062aa89cafd39a97971a2eb22653ff2a" > < 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#a062aa89cafd39a97971a2eb22653ff2a" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:a062aa89cafd39a97971a2eb22653ff2a" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:a37914d05ba1fe8848aa1b48cda719422" > < td class = "memItemLeft" align = "right" valign = "top" > void *  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../db/d84/malloc__dbg_8c.html#a37914d05ba1fe8848aa1b48cda719422" > malloc_dbg< / a > (size_t bytes, int line, const char *filename, const char *functionName)< / td > < / tr >
< tr class = "memdesc:a37914d05ba1fe8848aa1b48cda719422" > < 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#a37914d05ba1fe8848aa1b48cda719422" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:a37914d05ba1fe8848aa1b48cda719422" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
< tr class = "memitem:ab07f946b77155ca78d0e14e231a99f5d" > < td class = "memItemLeft" align = "right" valign = "top" > void *  < / td > < td class = "memItemRight" valign = "bottom" > < a class = "el" href = "../../db/d84/malloc__dbg_8c.html#ab07f946b77155ca78d0e14e231a99f5d" > calloc_dbg< / a > (size_t elementCount, size_t elementSize, int line, const char *filename, const char *functionName)< / td > < / tr >
< tr class = "memdesc:ab07f946b77155ca78d0e14e231a99f5d" > < 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#ab07f946b77155ca78d0e14e231a99f5d" > More...< / a > < br / > < / td > < / tr >
< tr class = "separator:ab07f946b77155ca78d0e14e231a99f5d" > < td class = "memSeparator" colspan = "2" >   < / td > < / tr >
2021-02-18 06:41:16 +08:00
< 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" >
2021-10-26 03:34:27 +08:00
< tr class = "heading" > < td colspan = "2" > < h2 class = "groupheader" > < a id = "var-members" name = "var-members" > < / a >
2021-02-18 06:41:16 +08:00
Variables< / h2 > < / td > < / tr >
2021-10-26 03:34:27 +08:00
< tr class = "memitem:afebd751704cd878d2e4b88499519c6e3" > < td class = "memItemLeft" align = "right" valign = "top" > < a id = "afebd751704cd878d2e4b88499519c6e3" name = "afebd751704cd878d2e4b88499519c6e3" > < / a >
< a class = "el" href = "../../db/d84/malloc__dbg_8c.html#ab6619fb17769f2e4e2e36c9ef2dda3c6" > mem_info< / a > *  < / td > < td class = "memItemRight" valign = "bottom" > < b > memoryInformation< / b > = NULL< / td > < / tr >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< 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" target = "_blank" > tinouduart33< / a > < / dd > < / dl >
2021-02-18 06:41:16 +08:00
< / div > < h2 class = "groupheader" > Typedef Documentation< / h2 >
2021-10-26 03:34:27 +08:00
< a id = "ab6619fb17769f2e4e2e36c9ef2dda3c6" name = "ab6619fb17769f2e4e2e36c9ef2dda3c6" > < / a >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< 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 >
2021-02-18 06:41:16 +08:00
< / div >
< / div >
< h2 class = "groupheader" > Function Documentation< / h2 >
2021-10-26 03:34:27 +08:00
< a id = "a062aa89cafd39a97971a2eb22653ff2a" name = "a062aa89cafd39a97971a2eb22653ff2a" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a062aa89cafd39a97971a2eb22653ff2a" > ◆ < / a > < / span > addMemInfo()< / h2 >
2021-02-18 06:41:16 +08:00
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
2021-10-26 03:34:27 +08:00
< td class = "memname" > < a class = "el" href = "../../db/d84/malloc__dbg_8c.html#ab6619fb17769f2e4e2e36c9ef2dda3c6" > mem_info< / a > * addMemInfo < / td >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< p > This function creates a new element and add it on top of the list < / p > < dl class = "params" > < dt > Parameters< / dt > < dd >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< div class = "fragment" > < div class = "line" > < a id = "l00052" name = "l00052" > < / a > < span class = "lineno" > 52< / span > {< / div >
< div class = "line" > < a id = "l00053" name = "l00053" > < / a > < span class = "lineno" > 53< / span > < a class = "code hl_struct" 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 hl_struct" 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 hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee" > malloc< / a > (< span class = "keyword" > sizeof< / span > (< a class = "code hl_struct" 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 id = "l00054" name = "l00054" > < / a > < span class = "lineno" > 54< / span > < span class = "keywordflow" > if< / span > (!newMemInfo)< / div >
< div class = "line" > < a id = "l00055" name = "l00055" > < / a > < span class = "lineno" > 55< / span > {< / div >
< div class = "line" > < a id = "l00056" name = "l00056" > < / a > < span class = "lineno" > 56< / span > < span class = "keywordflow" > return< / span > NULL;< / div >
< div class = "line" > < a id = "l00057" name = "l00057" > < / a > < span class = "lineno" > 57< / span > }< / div >
< div class = "line" > < a id = "l00058" name = "l00058" > < / a > < span class = "lineno" > 58< / span > < / div >
< div class = "line" > < a id = "l00059" name = "l00059" > < / a > < span class = "lineno" > 59< / span > newMemInfo-> < a class = "code hl_variable" 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 id = "l00060" name = "l00060" > < / a > < span class = "lineno" > 60< / span > newMemInfo-> < a class = "code hl_variable" 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 id = "l00061" name = "l00061" > < / a > < span class = "lineno" > 61< / span > newMemInfo-> < a class = "code hl_variable" 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 id = "l00062" name = "l00062" > < / a > < span class = "lineno" > 62< / span > newMemInfo-> < a class = "code hl_variable" 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 id = "l00063" name = "l00063" > < / a > < span class = "lineno" > 63< / span > newMemInfo-> < a class = "code hl_variable" 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 id = "l00064" name = "l00064" > < / a > < span class = "lineno" > 64< / span > newMemInfo-> < a class = "code hl_variable" 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 id = "l00065" name = "l00065" > < / a > < span class = "lineno" > 65< / span > newMemInfo-> < a class = "code hl_variable" 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 id = "l00066" name = "l00066" > < / a > < span class = "lineno" > 66< / span > < span class = "keywordflow" > if< / span > (< a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > )< / div >
< div class = "line" > < a id = "l00067" name = "l00067" > < / a > < span class = "lineno" > 67< / span > < a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > -> < a class = "code hl_variable" 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 id = "l00068" name = "l00068" > < / a > < span class = "lineno" > 68< / span > < / div >
< div class = "line" > < a id = "l00069" name = "l00069" > < / a > < span class = "lineno" > 69< / span > < span class = "keywordflow" > return< / span > newMemInfo;< / div >
< div class = "line" > < a id = "l00070" name = "l00070" > < / a > < span class = "lineno" > 70< / span > }< / div >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< a id = "ab07f946b77155ca78d0e14e231a99f5d" name = "ab07f946b77155ca78d0e14e231a99f5d" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#ab07f946b77155ca78d0e14e231a99f5d" > ◆ < / a > < / span > calloc_dbg()< / h2 >
2021-02-18 06:41:16 +08:00
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
2021-10-26 03:34:27 +08:00
< td class = "memname" > void * calloc_dbg < / td >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< 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 >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< div class = "fragment" > < div class = "line" > < a id = "l00175" name = "l00175" > < / a > < span class = "lineno" > 175< / span > {< / div >
< div class = "line" > < a id = "l00176" name = "l00176" > < / a > < span class = "lineno" > 176< / span > < span class = "keywordtype" > void< / span > * ptrToReturn = < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#afdddaa949a93c1ef559a638e98f9c21b" > calloc< / a > (elementCount, elementSize);< / div >
< div class = "line" > < a id = "l00177" name = "l00177" > < / a > < span class = "lineno" > 177< / span > < span class = "keywordflow" > if< / span > (!ptrToReturn)< / div >
< div class = "line" > < a id = "l00178" name = "l00178" > < / a > < span class = "lineno" > 178< / span > {< / div >
< div class = "line" > < a id = "l00179" name = "l00179" > < / a > < span class = "lineno" > 179< / span > < span class = "keywordflow" > return< / span > NULL;< / div >
< div class = "line" > < a id = "l00180" name = "l00180" > < / a > < span class = "lineno" > 180< / span > }< / div >
< div class = "line" > < a id = "l00181" name = "l00181" > < / a > < span class = "lineno" > 181< / span > < / div >
< div class = "line" > < a id = "l00182" 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 id = "l00183" name = "l00183" > < / a > < span class = "lineno" > 183< / span > < span class = "keywordflow" > if< / span > (!< a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950" > atexitCalled< / a > )< / div >
< div class = "line" > < a id = "l00184" name = "l00184" > < / a > < span class = "lineno" > 184< / span > {< / div >
< div class = "line" > < a id = "l00185" name = "l00185" > < / a > < span class = "lineno" > 185< / span > atexit(< a class = "code hl_function" 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 id = "l00186" name = "l00186" > < / a > < span class = "lineno" > 186< / span > < a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950" > atexitCalled< / a > = 1;< / div >
< div class = "line" > < a id = "l00187" name = "l00187" > < / a > < span class = "lineno" > 187< / span > }< / div >
< div class = "line" > < a id = "l00188" name = "l00188" > < / a > < span class = "lineno" > 188< / span > < / div >
< div class = "line" > < a id = "l00189" 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 id = "l00190" name = "l00190" > < / a > < span class = "lineno" > 190< / span > < a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > = < a class = "code hl_function" href = "../../db/d84/malloc__dbg_8c.html#a062aa89cafd39a97971a2eb22653ff2a" > addMemInfo< / a > (< a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > , ptrToReturn, elementCount * elementSize, line, filename, functionName);< / div >
< div class = "line" > < a id = "l00191" name = "l00191" > < / a > < span class = "lineno" > 191< / span > < span class = "keywordflow" > if< / span > (!< a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > )< / div >
< div class = "line" > < a id = "l00192" name = "l00192" > < / a > < span class = "lineno" > 192< / span > {< / div >
< div class = "line" > < a id = "l00193" name = "l00193" > < / a > < span class = "lineno" > 193< / span > < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768" > free< / a > (ptrToReturn);< / div >
< div class = "line" > < a id = "l00194" name = "l00194" > < / a > < span class = "lineno" > 194< / span > < span class = "keywordflow" > return< / span > NULL;< / div >
< div class = "line" > < a id = "l00195" name = "l00195" > < / a > < span class = "lineno" > 195< / span > }< / div >
< div class = "line" > < a id = "l00196" name = "l00196" > < / a > < span class = "lineno" > 196< / span > < / div >
< div class = "line" > < a id = "l00197" name = "l00197" > < / a > < span class = "lineno" > 197< / span > < span class = "keywordflow" > return< / span > ptrToReturn;< / div >
< div class = "line" > < a id = "l00198" name = "l00198" > < / a > < span class = "lineno" > 198< / span > }< / div >
< div class = "ttc" id = "amalloc__dbg_8c_html_a062aa89cafd39a97971a2eb22653ff2a" > < div class = "ttname" > < a href = "../../db/d84/malloc__dbg_8c.html#a062aa89cafd39a97971a2eb22653ff2a" > 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 >
2021-02-18 06:41:16 +08:00
< 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_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" >
2021-10-26 03:34:27 +08:00
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../db/d84/malloc__dbg_8c_ab07f946b77155ca78d0e14e231a99f5d_cgraph.svg" width = "240" height = "88" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
2021-02-18 06:41:16 +08:00
< / div >
< / div >
< / div >
< / div >
2021-10-26 03:34:27 +08:00
< a id = "a8ac3a93239838ac88c18df64c58b9275" name = "a8ac3a93239838ac88c18df64c58b9275" > < / a >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< p > This function is used to edit the number of bytes allocated at a specific line. < / p > < dl class = "params" > < dt > Parameters< / dt > < dd >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< div class = "fragment" > < div class = "line" > < a id = "l00108" name = "l00108" > < / a > < span class = "lineno" > 108< / span > {< / div >
< div class = "line" > < a id = "l00109" name = "l00109" > < / a > < span class = "lineno" > 109< / span > < span class = "keywordtype" > int< / span > counter = 0;< / div >
< div class = "line" > < a id = "l00110" name = "l00110" > < / a > < span class = "lineno" > 110< / span > < a class = "code hl_struct" 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 hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > ;< / div >
< div class = "line" > < a id = "l00111" name = "l00111" > < / a > < span class = "lineno" > 111< / span > < / div >
< div class = "line" > < a id = "l00112" name = "l00112" > < / a > < span class = "lineno" > 112< / span > < span class = "keywordflow" > while< / span > (counter != elemPos)< / div >
< div class = "line" > < a id = "l00113" name = "l00113" > < / a > < span class = "lineno" > 113< / span > {< / div >
< div class = "line" > < a id = "l00114" name = "l00114" > < / a > < span class = "lineno" > 114< / span > tmp = tmp-> next;< / div >
< div class = "line" > < a id = "l00115" name = "l00115" > < / a > < span class = "lineno" > 115< / span > counter++;< / div >
< div class = "line" > < a id = "l00116" name = "l00116" > < / a > < span class = "lineno" > 116< / span > }< / div >
< div class = "line" > < a id = "l00117" name = "l00117" > < / a > < span class = "lineno" > 117< / span > tmp-> bytes += bytes;< / div >
< div class = "line" > < a id = "l00118" name = "l00118" > < / a > < span class = "lineno" > 118< / span > }< / div >
2021-02-18 06:41:16 +08:00
< / div > <!-- fragment -->
< / div >
< / div >
2021-10-26 03:34:27 +08:00
< a id = "a3f9195a04ac8e8a9868ee3e416db7e8c" name = "a3f9195a04ac8e8a9868ee3e416db7e8c" > < / a >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< 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 >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< div class = "fragment" > < div class = "line" > < a id = "l00209" name = "l00209" > < / a > < span class = "lineno" > 209< / span > {< / div >
< div class = "line" > < a id = "l00210" name = "l00210" > < / a > < span class = "lineno" > 210< / span > < a class = "code hl_struct" 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 hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > ;< / div >
< div class = "line" > < a id = "l00211" name = "l00211" > < / a > < span class = "lineno" > 211< / span > < a class = "code hl_struct" 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 id = "l00212" name = "l00212" > < / a > < span class = "lineno" > 212< / span > < a class = "code hl_struct" 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 id = "l00213" name = "l00213" > < / a > < span class = "lineno" > 213< / span > < / div >
< div class = "line" > < a id = "l00214" 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 id = "l00215" name = "l00215" > < / a > < span class = "lineno" > 215< / span > < span class = "keywordflow" > if< / span > (tmp-> ptr == ptrToFree)< / div >
< div class = "line" > < a id = "l00216" name = "l00216" > < / a > < span class = "lineno" > 216< / span > {< / div >
< div class = "line" > < a id = "l00217" name = "l00217" > < / a > < span class = "lineno" > 217< / span > toFree = tmp;< / div >
< div class = "line" > < a id = "l00218" name = "l00218" > < / a > < span class = "lineno" > 218< / span > < a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > = tmp-> next;< / div >
< div class = "line" > < a id = "l00219" name = "l00219" > < / a > < span class = "lineno" > 219< / span > < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768" > free< / a > (toFree-> < a class = "code hl_variable" 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 id = "l00220" name = "l00220" > < / a > < span class = "lineno" > 220< / span > < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768" > free< / a > (toFree);< / div >
< div class = "line" > < a id = "l00221" name = "l00221" > < / a > < span class = "lineno" > 221< / span > < span class = "keywordflow" > if< / span > (< a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > )< / div >
< div class = "line" > < a id = "l00222" name = "l00222" > < / a > < span class = "lineno" > 222< / span > {< / div >
< div class = "line" > < a id = "l00223" name = "l00223" > < / a > < span class = "lineno" > 223< / span > < a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > -> < a class = "code hl_variable" 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 id = "l00224" name = "l00224" > < / a > < span class = "lineno" > 224< / span > }< / div >
< div class = "line" > < a id = "l00225" name = "l00225" > < / a > < span class = "lineno" > 225< / span > < span class = "keywordflow" > return< / span > ;< / div >
< div class = "line" > < a id = "l00226" name = "l00226" > < / a > < span class = "lineno" > 226< / span > }< / div >
< div class = "line" > < a id = "l00227" name = "l00227" > < / a > < span class = "lineno" > 227< / span > < / div >
< div class = "line" > < a id = "l00228" 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 id = "l00229" name = "l00229" > < / a > < span class = "lineno" > 229< / span > < span class = "keywordflow" > while< / span > (tmp)< / div >
< div class = "line" > < a id = "l00230" name = "l00230" > < / a > < span class = "lineno" > 230< / span > {< / div >
< div class = "line" > < a id = "l00231" 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 id = "l00232" name = "l00232" > < / a > < span class = "lineno" > 232< / span > {< / div >
< div class = "line" > < a id = "l00233" name = "l00233" > < / a > < span class = "lineno" > 233< / span > toFree = tmp;< / div >
< div class = "line" > < a id = "l00234" name = "l00234" > < / a > < span class = "lineno" > 234< / span > tmp = tmp-> next;< / div >
< div class = "line" > < a id = "l00235" name = "l00235" > < / a > < span class = "lineno" > 235< / span > previous = toFree-> < a class = "code hl_variable" 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 id = "l00236" name = "l00236" > < / a > < span class = "lineno" > 236< / span > < / div >
< div class = "line" > < a id = "l00237" name = "l00237" > < / a > < span class = "lineno" > 237< / span > < span class = "keywordflow" > if< / span > (previous)< / div >
< div class = "line" > < a id = "l00238" name = "l00238" > < / a > < span class = "lineno" > 238< / span > {< / div >
< div class = "line" > < a id = "l00239" name = "l00239" > < / a > < span class = "lineno" > 239< / span > previous-> < a class = "code hl_variable" 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 id = "l00240" name = "l00240" > < / a > < span class = "lineno" > 240< / span > }< / div >
< div class = "line" > < a id = "l00241" name = "l00241" > < / a > < span class = "lineno" > 241< / span > < span class = "keywordflow" > if< / span > (tmp)< / div >
< div class = "line" > < a id = "l00242" name = "l00242" > < / a > < span class = "lineno" > 242< / span > {< / div >
< div class = "line" > < a id = "l00243" name = "l00243" > < / a > < span class = "lineno" > 243< / span > tmp-> previous = previous;< / div >
< div class = "line" > < a id = "l00244" name = "l00244" > < / a > < span class = "lineno" > 244< / span > }< / div >
< div class = "line" > < a id = "l00245" name = "l00245" > < / a > < span class = "lineno" > 245< / span > < / div >
< div class = "line" > < a id = "l00246" name = "l00246" > < / a > < span class = "lineno" > 246< / span > < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768" > free< / a > (toFree-> < a class = "code hl_variable" 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 id = "l00247" name = "l00247" > < / a > < span class = "lineno" > 247< / span > < span class = "keywordflow" > if< / span > (toFree == < a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > )< / div >
< div class = "line" > < a id = "l00248" name = "l00248" > < / a > < span class = "lineno" > 248< / span > {< / div >
< div class = "line" > < a id = "l00249" name = "l00249" > < / a > < span class = "lineno" > 249< / span > < a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > = NULL;< / div >
< div class = "line" > < a id = "l00250" name = "l00250" > < / a > < span class = "lineno" > 250< / span > }< / div >
< div class = "line" > < a id = "l00251" name = "l00251" > < / a > < span class = "lineno" > 251< / span > < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768" > free< / a > (toFree);< / div >
< div class = "line" > < a id = "l00252" name = "l00252" > < / a > < span class = "lineno" > 252< / span > < span class = "keywordflow" > return< / span > ;< / div >
< div class = "line" > < a id = "l00253" name = "l00253" > < / a > < span class = "lineno" > 253< / span > }< / div >
< div class = "line" > < a id = "l00254" name = "l00254" > < / a > < span class = "lineno" > 254< / span > tmp = tmp-> next;< / div >
< div class = "line" > < a id = "l00255" name = "l00255" > < / a > < span class = "lineno" > 255< / span > }< / div >
< div class = "line" > < a id = "l00256" name = "l00256" > < / a > < span class = "lineno" > 256< / span > }< / div >
2021-02-18 06:41:16 +08:00
< / div > <!-- fragment -->
< / div >
< / div >
2021-10-26 03:34:27 +08:00
< a id = "acd08c54b257fb81e57f16c94690072f2" name = "acd08c54b257fb81e57f16c94690072f2" > < / a >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< 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 >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< div class = "fragment" > < div class = "line" > < a id = "l00080" name = "l00080" > < / a > < span class = "lineno" > 80< / span > {< / div >
< div class = "line" > < a id = "l00081" name = "l00081" > < / a > < span class = "lineno" > 81< / span > < a class = "code hl_struct" 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 hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > ;< / div >
< div class = "line" > < a id = "l00082" name = "l00082" > < / a > < span class = "lineno" > 82< / span > < span class = "keywordtype" > int< / span > counter = 0;< / div >
< div class = "line" > < a id = "l00083" name = "l00083" > < / a > < span class = "lineno" > 83< / span > < span class = "keywordtype" > int< / span > len = strlen(filename);< / div >
< div class = "line" > < a id = "l00084" name = "l00084" > < / a > < span class = "lineno" > 84< / span > < / div >
< div class = "line" > < a id = "l00085" name = "l00085" > < / a > < span class = "lineno" > 85< / span > < span class = "keywordflow" > while< / span > (tmp)< / div >
< div class = "line" > < a id = "l00086" name = "l00086" > < / a > < span class = "lineno" > 86< / span > {< / div >
< div class = "line" > < a id = "l00087" name = "l00087" > < / a > < span class = "lineno" > 87< / span > < span class = "keywordflow" > if< / span > (len == strlen(tmp-> fileName))< / div >
< div class = "line" > < a id = "l00088" name = "l00088" > < / a > < span class = "lineno" > 88< / span > {< / div >
< div class = "line" > < a id = "l00089" 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 id = "l00090" name = "l00090" > < / a > < span class = "lineno" > 90< / span > {< / div >
< div class = "line" > < a id = "l00091" name = "l00091" > < / a > < span class = "lineno" > 91< / span > < span class = "keywordflow" > return< / span > counter;< / div >
< div class = "line" > < a id = "l00092" name = "l00092" > < / a > < span class = "lineno" > 92< / span > }< / div >
< div class = "line" > < a id = "l00093" name = "l00093" > < / a > < span class = "lineno" > 93< / span > }< / div >
< div class = "line" > < a id = "l00094" name = "l00094" > < / a > < span class = "lineno" > 94< / span > tmp = tmp-> next;< / div >
< div class = "line" > < a id = "l00095" name = "l00095" > < / a > < span class = "lineno" > 95< / span > counter++;< / div >
< div class = "line" > < a id = "l00096" name = "l00096" > < / a > < span class = "lineno" > 96< / span > }< / div >
< div class = "line" > < a id = "l00097" name = "l00097" > < / a > < span class = "lineno" > 97< / span > < span class = "keywordflow" > return< / span > -1;< / div >
< div class = "line" > < a id = "l00098" name = "l00098" > < / a > < span class = "lineno" > 98< / span > }< / div >
2021-02-18 06:41:16 +08:00
< / div > <!-- fragment -->
< / div >
< / div >
2021-10-26 03:34:27 +08:00
< a id = "a37914d05ba1fe8848aa1b48cda719422" name = "a37914d05ba1fe8848aa1b48cda719422" > < / a >
< h2 class = "memtitle" > < span class = "permalink" > < a href = "#a37914d05ba1fe8848aa1b48cda719422" > ◆ < / a > < / span > malloc_dbg()< / h2 >
2021-02-18 06:41:16 +08:00
< div class = "memitem" >
< div class = "memproto" >
< table class = "memname" >
< tr >
2021-10-26 03:34:27 +08:00
< td class = "memname" > void * malloc_dbg < / td >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< 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 >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< div class = "fragment" > < div class = "line" > < a id = "l00130" name = "l00130" > < / a > < span class = "lineno" > 130< / span > {< / div >
< div class = "line" > < a id = "l00131" name = "l00131" > < / a > < span class = "lineno" > 131< / span > < span class = "keywordtype" > void< / span > * ptrToReturn = < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a725f50ecaf1959d96de79b36b4788fee" > malloc< / a > (bytes);< / div >
< div class = "line" > < a id = "l00132" name = "l00132" > < / a > < span class = "lineno" > 132< / span > < span class = "keywordtype" > int< / span > pos = 0;< / div >
< div class = "line" > < a id = "l00133" name = "l00133" > < / a > < span class = "lineno" > 133< / span > < span class = "keywordflow" > if< / span > (!ptrToReturn)< / div >
< div class = "line" > < a id = "l00134" name = "l00134" > < / a > < span class = "lineno" > 134< / span > {< / div >
< div class = "line" > < a id = "l00135" name = "l00135" > < / a > < span class = "lineno" > 135< / span > < span class = "keywordflow" > return< / span > NULL;< / div >
< div class = "line" > < a id = "l00136" name = "l00136" > < / a > < span class = "lineno" > 136< / span > }< / div >
< div class = "line" > < a id = "l00137" name = "l00137" > < / a > < span class = "lineno" > 137< / span > < / div >
< div class = "line" > < a id = "l00138" 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 id = "l00139" name = "l00139" > < / a > < span class = "lineno" > 139< / span > < span class = "keywordflow" > if< / span > (!< a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950" > atexitCalled< / a > )< / div >
< div class = "line" > < a id = "l00140" name = "l00140" > < / a > < span class = "lineno" > 140< / span > {< / div >
< div class = "line" > < a id = "l00141" name = "l00141" > < / a > < span class = "lineno" > 141< / span > atexit(< a class = "code hl_function" 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 id = "l00142" name = "l00142" > < / a > < span class = "lineno" > 142< / span > < a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#ad04afbbcb9f0f10bc7628ec4f0d7c950" > atexitCalled< / a > = 1;< / div >
< div class = "line" > < a id = "l00143" name = "l00143" > < / a > < span class = "lineno" > 143< / span > }< / div >
< div class = "line" > < a id = "l00144" name = "l00144" > < / a > < span class = "lineno" > 144< / span > < / div >
< div class = "line" > < a id = "l00145" name = "l00145" > < / a > < span class = "lineno" > 145< / span > pos = < a class = "code hl_function" href = "../../db/d84/malloc__dbg_8c.html#acd08c54b257fb81e57f16c94690072f2" > inList< / a > (filename, line);< / div >
< div class = "line" > < a id = "l00146" name = "l00146" > < / a > < span class = "lineno" > 146< / span > < span class = "keywordflow" > if< / span > (pos == -1)< / div >
< div class = "line" > < a id = "l00147" name = "l00147" > < / a > < span class = "lineno" > 147< / span > {< / div >
< div class = "line" > < a id = "l00148" 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 id = "l00149" name = "l00149" > < / a > < span class = "lineno" > 149< / span > < a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > = < a class = "code hl_function" href = "../../db/d84/malloc__dbg_8c.html#a062aa89cafd39a97971a2eb22653ff2a" > addMemInfo< / a > (< a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > , ptrToReturn, bytes, line, filename, functionName);< / div >
< div class = "line" > < a id = "l00150" name = "l00150" > < / a > < span class = "lineno" > 150< / span > < span class = "keywordflow" > if< / span > (!< a class = "code hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > )< / div >
< div class = "line" > < a id = "l00151" name = "l00151" > < / a > < span class = "lineno" > 151< / span > {< / div >
< div class = "line" > < a id = "l00152" name = "l00152" > < / a > < span class = "lineno" > 152< / span > < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768" > free< / a > (ptrToReturn);< / div >
< div class = "line" > < a id = "l00153" name = "l00153" > < / a > < span class = "lineno" > 153< / span > < span class = "keywordflow" > return< / span > NULL;< / div >
< div class = "line" > < a id = "l00154" name = "l00154" > < / a > < span class = "lineno" > 154< / span > }< / div >
< div class = "line" > < a id = "l00155" name = "l00155" > < / a > < span class = "lineno" > 155< / span > }< / div >
< div class = "line" > < a id = "l00156" name = "l00156" > < / a > < span class = "lineno" > 156< / span > < span class = "keywordflow" > else< / span > < / div >
< div class = "line" > < a id = "l00157" name = "l00157" > < / a > < span class = "lineno" > 157< / span > {< / div >
< div class = "line" > < a id = "l00158" name = "l00158" > < / a > < span class = "lineno" > 158< / span > < a class = "code hl_function" href = "../../db/d84/malloc__dbg_8c.html#a8ac3a93239838ac88c18df64c58b9275" > editInfo< / a > (pos, bytes);< / div >
< div class = "line" > < a id = "l00159" name = "l00159" > < / a > < span class = "lineno" > 159< / span > }< / div >
< div class = "line" > < a id = "l00160" name = "l00160" > < / a > < span class = "lineno" > 160< / span > < span class = "keywordflow" > return< / span > ptrToReturn;< / div >
< div class = "line" > < a id = "l00161" name = "l00161" > < / a > < span class = "lineno" > 161< / span > }< / div >
2021-02-18 06:41:16 +08:00
< 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" >
2021-10-26 03:34:27 +08:00
< div class = "center" > < iframe scrolling = "no" frameborder = "0" src = "../../db/d84/malloc__dbg_8c_a37914d05ba1fe8848aa1b48cda719422_cgraph.svg" width = "246" height = "190" > < p > < b > This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.< / b > < / p > < / iframe >
2021-02-18 06:41:16 +08:00
< / div >
< / div >
< / div >
< / div >
2021-10-26 03:34:27 +08:00
< a id = "a2a47e4c38db8c00b80248e5535adf797" name = "a2a47e4c38db8c00b80248e5535adf797" > < / a >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< 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 id = "l00265" name = "l00265" > < / a > < span class = "lineno" > 265< / span > {< / div >
< div class = "line" > < a id = "l00266" name = "l00266" > < / a > < span class = "lineno" > 266< / span > < a class = "code hl_struct" 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 hl_variable" href = "../../db/d84/malloc__dbg_8c.html#afebd751704cd878d2e4b88499519c6e3" > memoryInformation< / a > ;< / div >
< div class = "line" > < a id = "l00267" name = "l00267" > < / a > < span class = "lineno" > 267< / span > < a class = "code hl_struct" 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 id = "l00268" name = "l00268" > < / a > < span class = "lineno" > 268< / span > < span class = "keywordtype" > size_t< / span > sum = 0;< / div >
< div class = "line" > < a id = "l00269" name = "l00269" > < / a > < span class = "lineno" > 269< / span > < span class = "keywordtype" > int< / span > nbBlocks = 0;< / div >
< div class = "line" > < a id = "l00270" name = "l00270" > < / a > < span class = "lineno" > 270< / span > < / div >
< div class = "line" > < a id = "l00271" name = "l00271" > < / a > < span class = "lineno" > 271< / span > < span class = "keywordflow" > if< / span > (tmp)< / div >
< div class = "line" > < a id = "l00272" name = "l00272" > < / a > < span class = "lineno" > 272< / span > {< / div >
< div class = "line" > < a id = "l00273" name = "l00273" > < / a > < span class = "lineno" > 273< / span > printf(< span class = "stringliteral" > " Memory Leaks detected.\n" < / span > );< / div >
< div class = "line" > < a id = "l00274" name = "l00274" > < / a > < span class = "lineno" > 274< / span > }< / div >
< div class = "line" > < a id = "l00275" name = "l00275" > < / a > < span class = "lineno" > 275< / span > < / div >
< div class = "line" > < a id = "l00276" name = "l00276" > < / a > < span class = "lineno" > 276< / span > < span class = "keywordflow" > while< / span > (tmp)< / div >
< div class = "line" > < a id = "l00277" name = "l00277" > < / a > < span class = "lineno" > 277< / span > {< / div >
< div class = "line" > < a id = "l00278" name = "l00278" > < / a > < span class = "lineno" > 278< / span > previous = tmp;< / div >
< div class = "line" > < a id = "l00279" 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 id = "l00280" 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 id = "l00281" name = "l00281" > < / a > < span class = "lineno" > 281< / span > printf(< span class = "stringliteral" > " \n====================================\n" < / span > );< / div >
< div class = "line" > < a id = "l00282" name = "l00282" > < / a > < span class = "lineno" > 282< / span > sum += tmp-> bytes;< / div >
< div class = "line" > < a id = "l00283" name = "l00283" > < / a > < span class = "lineno" > 283< / span > tmp = tmp-> next;< / div >
< div class = "line" > < a id = "l00284" name = "l00284" > < / a > < span class = "lineno" > 284< / span > < a class = "code hl_define" href = "../../d2/ddd/malloc__dbg_8h.html#a9cc854374299a1dd933bf62029761768" > free< / a > (previous);< / div >
< div class = "line" > < a id = "l00285" name = "l00285" > < / a > < span class = "lineno" > 285< / span > nbBlocks++;< / div >
< div class = "line" > < a id = "l00286" name = "l00286" > < / a > < span class = "lineno" > 286< / span > }< / div >
< div class = "line" > < a id = "l00287" name = "l00287" > < / a > < span class = "lineno" > 287< / span > < / div >
< div class = "line" > < a id = "l00288" 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 id = "l00289" name = "l00289" > < / a > < span class = "lineno" > 289< / span > }< / div >
2021-02-18 06:41:16 +08:00
< / div > <!-- fragment -->
< / div >
< / div >
< h2 class = "groupheader" > Variable Documentation< / h2 >
2021-10-26 03:34:27 +08:00
< a id = "ad04afbbcb9f0f10bc7628ec4f0d7c950" name = "ad04afbbcb9f0f10bc7628ec4f0d7c950" > < / a >
2021-02-18 06:41:16 +08:00
< 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 >
2021-10-26 03:34:27 +08:00
< p > This one is used to know if we already call the atexit function. < / p >
2021-02-18 06:41:16 +08:00
< / 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 >
2021-10-26 03:34:27 +08:00
< 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.2 < / li >
2021-02-18 06:41:16 +08:00
< / ul >
< / div >
< / body >
< / html >