Skip to content

Commit

Permalink
fix func kcl_alloc. (#1782)
Browse files Browse the repository at this point in the history
fix func kcl_alloc. Init ptr value when alloc

Signed-off-by: he1pa <[email protected]>
  • Loading branch information
He1pa authored Dec 17, 2024
1 parent 39c7503 commit 78346e0
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kclvm/src/capi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use kclvm_runner::runner::KCL_RUNTIME_PANIC_RECORD;
use std::alloc::{alloc, dealloc, Layout};
use std::ffi::c_char;
use std::ffi::{CStr, CString};
use std::mem;
use std::{mem, ptr};

use crate::{intern_fmt, intern_run};

Expand All @@ -18,6 +18,7 @@ pub unsafe extern "C" fn kcl_malloc(size: usize) -> *mut u8 {
if layout.size() > 0 {
let ptr = alloc(layout);
if !ptr.is_null() {
ptr::write_bytes(ptr, 0, size);
ptr
} else {
std::alloc::handle_alloc_error(layout);
Expand Down

0 comments on commit 78346e0

Please sign in to comment.