MCPcopy Create free account
hub / github.com/cgsecurity/testdisk / MALLOC

Function MALLOC

src/common.c:61–103  ·  view source on GitHub ↗

coverity[+alloc] */

Source from the content-addressed store, hash-verified

59
60/* coverity[+alloc] */
61void *MALLOC(size_t size)
62{
63 void *res;
64 assert(size>0);
65 /* Warning, memory leak checker must be posix_memalign/memalign aware, otherwise *
66 * reports may look strange. Aligned memory is required if the buffer is *
67 * used for read/write operation with a file opened with O_DIRECT */
68#if defined(HAVE_POSIX_MEMALIGN)
69 if(size>=512)
70 {
71 if(posix_memalign(&res,4096,size)==0)
72 {
73 memset(res,0,size);
74 return res;
75 }
76 }
77#elif defined(HAVE_MEMALIGN)
78 if(size>=512)
79 {
80 if((res=memalign(4096, size))!=NULL)
81 {
82 memset(res,0,size);
83 return res;
84 }
85 }
86#endif
87#ifdef DISABLED_FOR_FRAMAC
88 if((res=calloc(1,size))==NULL)
89 {
90 exit(EXIT_FAILURE);
91 }
92#else
93 if((res=malloc(size))==NULL)
94 {
95 log_critical("\nCan't allocate %lu bytes of memory.\n", (long unsigned)size);
96 log_close();
97 exit(EXIT_FAILURE);
98 }
99 memset(res,0,size);
100#endif
101 /*@ assert \valid((char *)res + (0 .. size - 1)); */
102 return res;
103}
104
105#ifndef HAVE_SNPRINTF
106int snprintf(char *str, size_t size, const char *format, ...)

Callers 15

check_HPFSFunction · 0.85
search_NTFS_from_backupFunction · 0.85
search_partFunction · 0.85
check_VMFSFunction · 0.85
check_LVMFunction · 0.85
check_LVM2Function · 0.85
find_sectors_per_clusterFunction · 0.85
photorec_bfFunction · 0.85
photorec_bf_auxFunction · 0.85
read_part_gpt_auxFunction · 0.85
get_dos_drive_listFunction · 0.85

Calls 1

log_closeFunction · 0.85

Tested by

no test coverage detected