Prevent OOM
This commit is contained in:
@@ -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; }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user