1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

fix further memory leaks

This commit is contained in:
sdeml 2019-01-18 17:29:53 +01:00
parent 710eab6eac
commit 91bf2c0ea8

View file

@ -7,7 +7,7 @@
extern crate libc; extern crate libc;
use self::libc::{c_char, c_int, uint8_t}; use self::libc::{c_char, c_int, uint8_t};
use std::ffi::CString; use std::ffi::CStr;
use std::string::String; use std::string::String;
use zokrates_field::field::Field; use zokrates_field::field::Field;
@ -18,8 +18,11 @@ extern "C" {
} }
pub fn get_sha256round_constraints() -> String { pub fn get_sha256round_constraints() -> String {
let a = unsafe { CString::from_raw(_sha256RoundConstraints()) }; let c_buf: *const c_char = unsafe { _sha256RoundConstraints() };
a.into_string().unwrap() let c_str: &CStr = unsafe { CStr::from_ptr(c_buf) };
let str_slice: &str = c_str.to_str().unwrap();
let str_buf: String = str_slice.to_owned();
str_buf
} }
pub fn get_sha256round_witness<T: Field>(inputs: &Vec<T>) -> String { pub fn get_sha256round_witness<T: Field>(inputs: &Vec<T>) -> String {
@ -27,14 +30,12 @@ pub fn get_sha256round_witness<T: Field>(inputs: &Vec<T>) -> String {
for (index, value) in inputs.into_iter().enumerate() { for (index, value) in inputs.into_iter().enumerate() {
inputs_arr[index] = vec_as_u8_32_array(&value.into_byte_vector()); inputs_arr[index] = vec_as_u8_32_array(&value.into_byte_vector());
} }
let c_buf: *const c_char =
let a = unsafe { unsafe { _sha256RoundWitness(inputs_arr[0].as_ptr(), inputs.len() as i32) };
CString::from_raw(_sha256RoundWitness( let c_str: &CStr = unsafe { CStr::from_ptr(c_buf) };
inputs_arr[0].as_ptr(), let str_slice: &str = c_str.to_str().unwrap();
inputs.len() as i32, let str_buf: String = str_slice.to_owned();
)) str_buf
};
a.into_string().unwrap()
} }
// utility function. Converts a Fields vector-based byte representation to fixed size array. // utility function. Converts a Fields vector-based byte representation to fixed size array.