请教一下两个问题,如下
为什么path分配空间后,最后面写kfree(path)会导致crash,这样写法是错的吗?
另外code写free_token = token,然后最后kfree(free_token),为什么要多写一个指标去free?
谢谢
int test(struct device *dev, const char *p_i8_buf, size_t count)
{
int i32_ret = 0;
char *temp_buf, *token, *path;
char *free_temp_buf, *free_token;
unsigned long fun = 0;
const char *delim = " ,";
temp_buf = kzalloc(RAYDIUM_FW_BIN_PATH_LENGTH + 1, GFP_KERNEL);
if (temp_buf == NULL)
{
return -ENOMEM;
}
token = kzalloc(RAYDIUM_FW_BIN_PATH_LENGTH + 1, GFP_KERNEL);
if (token == NULL) {
kfree(temp_buf);
return -ENOMEM;
}
path = kzalloc(RAYDIUM_FW_BIN_PATH_LENGTH + 1, GFP_KERNEL);
if (path == NULL) {
kfree(temp_buf);
kfree(token);
return -ENOMEM;
}
free_token = token;
free_temp_buf = temp_buf;
strlcpy(temp_buf, p_i8_buf, count);
token = strsep(&temp_buf, delim);
if(token == NULL)
{
kfree(free_token);
kfree(free_temp_buf);
kfree(path);
return -EINVAL;
}
i32_ret = kstrtoul(token, 16, &fun);
if (i32_ret < 0) {
kfree(free_token);
kfree(free_temp_buf);
kfree(path);
return i32_ret;
}
path = strsep(&temp_buf, delim);//log path
parse(dev, fun, path);
kfree(free_token);
kfree(free_temp_buf);
//kfree(path); //will not crash <