fix memleaks in luv_cpu_info
`uv_cpu_info` Gets information about the CPUs on the system.
The cpu_infos array will have count elements and needs to be freed with uv_free_cpu_info().
`uv_free_cpu_info` should be called when get cpu info fail.
@@ -222,10 +222,14 @@ static int luv_getrusage(lua_State* L) {
}
static int luv_cpu_info(lua_State* L) {
- uv_cpu_info_t* cpu_infos;
- int count, i;
+ uv_cpu_info_t* cpu_infos = NULL;
+ int count = 0, i;
int ret = uv_cpu_info(&cpu_infos, &count);
- if (ret < 0) return luv_error(L, ret);
+ if (ret < 0)
+ {
+ uv_free_cpu_info(cpu_infos, count);
+ return luv_error(L, ret);
+ }
lua_newtable(L);
for (i = 0; i < count; i++) {
