mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-21 21:19:35 +00:00
replace malloc with calloc
malloc: allocate a block of memory, the contents of the block are undefined. calloc: allocate a block of memory for an array of num elements and initializes all its bits to zero. Signed-off-by: yechunliang <yechunliangcn@163.com>
This commit is contained in:
parent
9aa9a77457
commit
2e2f02edeb
@ -118,7 +118,7 @@ vm_open(const char *name)
|
|||||||
int error, retry = 10;
|
int error, retry = 10;
|
||||||
uuid_t vm_uuid;
|
uuid_t vm_uuid;
|
||||||
|
|
||||||
ctx = malloc(sizeof(struct vmctx) + strlen(name) + 1);
|
ctx = calloc(1, sizeof(struct vmctx) + strlen(name) + 1);
|
||||||
assert(ctx != NULL);
|
assert(ctx != NULL);
|
||||||
assert(devfd == -1);
|
assert(devfd == -1);
|
||||||
|
|
||||||
|
@ -1105,9 +1105,8 @@ vrtc_init(struct vmctx *ctx, int local_time)
|
|||||||
time_t curtime;
|
time_t curtime;
|
||||||
struct inout_port rtc_addr, rtc_data;
|
struct inout_port rtc_addr, rtc_data;
|
||||||
|
|
||||||
vrtc = malloc(sizeof(struct vrtc));
|
vrtc = calloc(1, sizeof(struct vrtc));
|
||||||
assert(vrtc != NULL);
|
assert(vrtc != NULL);
|
||||||
memset(vrtc, 0, sizeof(struct vrtc));
|
|
||||||
vrtc->vm = ctx;
|
vrtc->vm = ctx;
|
||||||
ctx->vrtc = vrtc;
|
ctx->vrtc = vrtc;
|
||||||
|
|
||||||
|
@ -340,12 +340,11 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
/* how many cpus */
|
/* how many cpus */
|
||||||
pcpu_num = get_cpu_num();
|
pcpu_num = get_cpu_num();
|
||||||
reader = malloc(sizeof(reader_struct) * pcpu_num);
|
reader = calloc(1, sizeof(reader_struct) * pcpu_num);
|
||||||
if (!reader) {
|
if (!reader) {
|
||||||
pr_err("Failed to allocate reader memory\n");
|
pr_err("Failed to allocate reader memory\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
memset(reader, 0, sizeof(reader_struct) * pcpu_num);
|
|
||||||
|
|
||||||
/* create dir for trace file */
|
/* create dir for trace file */
|
||||||
if (create_trace_file_dir(trace_file_dir)) {
|
if (create_trace_file_dir(trace_file_dir)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user