Prevent OOM

This commit is contained in:
2026-06-18 05:55:31 +10:00
parent ebba70b9d9
commit b3436a61ee
44 changed files with 1797 additions and 66 deletions
+39
View File
@@ -3093,3 +3093,42 @@ extern "C" ANSULT_API int GetANSLoggerErrorEvents(int clearAfterRead, LStrHandle
}
catch (...) { return -1; }
}
// ---------------------------------------------------------------------------
// GetANSLoggerErrorEventsSinceLastCall — watermark-based incremental read.
// Stores highest EventRecordID seen in HKCU; subsequent calls return only
// newer events. No admin needed for the skip (only for clearAfterRead).
// ---------------------------------------------------------------------------
extern "C" ANSULT_API int GetANSLoggerErrorEventsSinceLastCallCpp(int clearAfterRead, std::string& result) {
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsSinceLastCallCpp: clearAfterRead=%d", clearAfterRead);
try {
result = ANSCENTER::ANSUtilities::GetANSLoggerErrorEventsSinceLastCall(clearAfterRead != 0);
return 1;
}
catch (const std::exception& e) {
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsSinceLastCallCpp threw: %s", e.what());
result.clear();
return 0;
}
catch (...) {
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsSinceLastCallCpp threw unknown");
result.clear();
return 0;
}
}
extern "C" ANSULT_API int GetANSLoggerErrorEventsSinceLastCall(int clearAfterRead, LStrHandle result) {
ANS_DBG("ANSUTIL", "GetANSLoggerErrorEventsSinceLastCall: clearAfterRead=%d", clearAfterRead);
if (!result) return -1;
try {
std::string s;
GetANSLoggerErrorEventsSinceLastCallCpp(clearAfterRead, s);
int size = static_cast<int>(s.size());
MgErr error = DSSetHandleSize(result, sizeof(int32) + size * sizeof(uChar));
if (error != noErr) return -2;
(*result)->cnt = size;
if (size > 0) memcpy((*result)->str, s.data(), size);
return 1;
}
catch (...) { return -1; }
}