harden(net): ApiCall onFinished reply 快照防御 + 构造 Q_ASSERT(reply)(评审 H3/L1)

This commit is contained in:
gaozheng 2026-06-11 19:59:23 +08:00
parent 8f94443323
commit f74d47e62e
1 changed files with 5 additions and 2 deletions

View File

@ -6,13 +6,16 @@
namespace geopro::net { namespace geopro::net {
ApiCall::ApiCall(QNetworkReply* reply, QObject* parent) : IApiCall(parent), reply_(reply) { ApiCall::ApiCall(QNetworkReply* reply, QObject* parent) : IApiCall(parent), reply_(reply) {
Q_ASSERT(reply); // 契约:不接受 null replyNAM get/post 正常不返回 null
QObject::connect(reply_, &QNetworkReply::finished, this, &ApiCall::onFinished); QObject::connect(reply_, &QNetworkReply::finished, this, &ApiCall::onFinished);
} }
void ApiCall::onFinished() { void ApiCall::onFinished() {
if (aborted_) return; // §5.0 入口守卫:迟到信号闸门 if (aborted_) return; // §5.0 入口守卫:迟到信号闸门
ApiResponse resp = buildResponse(reply_); QNetworkReply* reply = reply_.data(); // 快照:意图明确 + 防御 reply_ 中途被置空
if (reply_) reply_->deleteLater(); if (!reply) return;
ApiResponse resp = buildResponse(reply);
reply->deleteLater();
emit finished(resp); emit finished(resp);
deleteLater(); deleteLater();
} }