Fix memory leaks in C API examples

This commit is contained in:
Amanieu d'Antras
2021-11-15 15:58:40 +00:00
parent 88f1b19ff1
commit cff3e18a34
4 changed files with 6 additions and 6 deletions

View File

@ -103,12 +103,15 @@ int main(int argc, const char* argv[]) {
wasmer_last_error_message(error_message, error_length);
printf("Attempted to set an immutable global: `%s`\n", error_message);
free(error_message);
}
wasm_val_t some_set_value = WASM_F32_VAL(21);
wasm_global_set(some, &some_set_value);
printf("`some` value: %.1f\n", some_value.of.f32);
wasm_globaltype_delete(one_type);
wasm_globaltype_delete(some_type);
wasm_module_delete(module);
wasm_extern_vec_delete(&exports);
wasm_instance_delete(instance);

View File

@ -63,6 +63,7 @@ int main(int argc, const char* argv[]) {
printf("Instantiating module...\n");
wasm_instance_t* instance = wasm_instance_new(store, module, &import_object, NULL);
wasm_extern_vec_delete(&import_object);
if (!instance) {
printf("> Error instantiating module!\n");

View File

@ -15,6 +15,7 @@ int main(int argc, const char* argv[]) {
wasm_byte_vec_new(&wat, strlen(wat_string), wat_string);
wasm_byte_vec_t wasm_bytes;
wat2wasm(&wat, &wasm_bytes);
wasm_byte_vec_delete(&wat);
printf("Creating the store...\n");
wasm_engine_t* engine = wasm_engine_new();

View File

@ -69,13 +69,7 @@ int main(int argc, const char* argv[]) {
// Instantiate.
printf("Instantiating module...\n");
wasm_importtype_vec_t import_types;
wasm_module_imports(module, &import_types);
wasm_extern_vec_t imports;
wasm_extern_vec_new_uninitialized(&imports, import_types.size);
wasm_importtype_vec_delete(&import_types);
bool get_imports_result = wasi_get_imports(store, module, wasi_env, &imports);
if (!get_imports_result) {
@ -153,6 +147,7 @@ int main(int argc, const char* argv[]) {
fclose(memory_stream);
printf("WASI Stdout: `%.*s`\n", (int) stdout_size, stdout);
free(stdout);
}