Sysctl: returns error on failed string fetch and removes malloc null check

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
Carter Li
2026-04-30 09:31:28 +08:00
parent cd25803e32
commit b68ad3626c
+4 -5
View File
@@ -47,10 +47,12 @@ const char* ffSysctlGetString(const char* propName, FFstrbuf* result) {
ffStrbufEnsureFree(result, (uint32_t) neededLength - 1);
if (sysctlbyname(propName, result->chars + result->length, &neededLength, NULL, 0) == 0) {
result->length += (uint32_t) neededLength - 1;
if (sysctlbyname(propName, result->chars + result->length, &neededLength, NULL, 0) != 0) {
return "sysctlbyname() failed to retrieve string data";
}
result->length += (uint32_t) neededLength - 1;
result->chars[result->length] = '\0';
return NULL;
@@ -81,9 +83,6 @@ void* ffSysctlGetData(int* request, u_int requestLength, size_t* resultLength) {
}
void* data = malloc(*resultLength);
if (data == NULL) {
return NULL;
}
if (sysctl(request, requestLength, data, resultLength, NULL, 0) != 0) {
free(data);