小编cod*_*ppy的帖子

为什么从 C 调用 Rust 库会导致内存泄漏?

我试图证明 C 可以调用 Rust 库。它有效,但是当我监视程序的内存使用情况时,它不断变得越来越大。

货物.toml:

[lib]
name="test_ccallr"
crate-type=["cdylib"]
path = "src/lib.rs"

[dependencies]
libc = "0.2"
Run Code Online (Sandbox Code Playgroud)

C代码:

[lib]
name="test_ccallr"
crate-type=["cdylib"]
path = "src/lib.rs"

[dependencies]
libc = "0.2"
Run Code Online (Sandbox Code Playgroud)

我使用以下命令构建 C 代码:

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>

struct Payload_t{
    char* data;
    int len;
};

int show_str(char* raw, struct Payload_t *data);

int main()
{
    while(1){
        char * p_raw = "hlease print it !ello this is string from c, please print it !";
        char * p_raw_ = "hhello this is another …
Run Code Online (Sandbox Code Playgroud)

c memory memory-leaks ffi rust

0
推荐指数
1
解决办法
505
查看次数

标签 统计

c ×1

ffi ×1

memory ×1

memory-leaks ×1

rust ×1