Conversation
| ml_loge ("%s", e.what ()); | ||
| svcdb_finalize (); | ||
| } | ||
|
|
There was a problem hiding this comment.
Code below is right ?
try {
g_svcdb_instance = new MLServiceDB (path);
g_svcdb_instance->connectDB ();
g_assert (g_svcdb_instance); // when succeed ?
} catch (const std::exception &e) {
ml_loge ("%s", e.what ());
svcdb_finalize ();
}
There was a problem hiding this comment.
no, db instance should be a valid pointer when calling initialization.
| } | ||
|
|
||
| g_svcdb_instance = new MLServiceDB (path); | ||
| try { |
There was a problem hiding this comment.
add g_svcdb_insatnce = nullptr after line 876.
There was a problem hiding this comment.
I used svcdb_finalize()
| g_svcdb_instance->connectDB (); | ||
| } catch (const std::exception &e) { | ||
| ml_loge ("%s", e.what ()); | ||
| svcdb_finalize (); |
There was a problem hiding this comment.
This is CURSOR's review, and I agree with it:
PR #70 ([ServiceDB] handle exception, commit 0183218) 기준으로 변경분만 리뷰했습니다.
주요 Findings (심각도 순)
[Critical] 예외 경로에서 use-after-free / double-delete 가능
위치: daemon/service-db.cc:874-877, 882-885, 895-899
문제:
기존 인스턴스가 있을 때 delete g_svcdb_instance; 후 nullptr로 초기화하지 않습니다.
그 다음 new MLServiceDB(path)가 예외를 던지면(예: std::bad_alloc, ctor 예외), catch에서 svcdb_finalize()를 호출하면서 이미 해제된 포인터를 다시 disconnectDB()/delete 할 수 있습니다.
제안:
delete 직후 g_svcdb_instance = nullptr;를 즉시 설정.
catch에서 svcdb_finalize() 대신 안전하게 상태만 정리(또는 지역 포인터/std::unique_ptr로 생성 완료 후 전역 포인터에 대입).
[High] “예외 처리” 목적이 실제로는 달성되지 않음 (assert로 종료)
위치: daemon/service-db.cc:879-888
문제:
catch에서 예외를 로그하고 정리한 뒤에도 g_assert(g_svcdb_instance);가 실행됩니다.
실패 시 g_svcdb_instance == nullptr이므로 assert로 프로세스 종료 가능 → 커밋 메시지의 “Handle exception”과 동작 불일치.
제안:
실패를 호출자에게 전달 가능한 형태로 변경(svcdb_initialize 반환형을 int/bool로), 최소한 assert 대신 명시적 에러 경로 처리 필요.
There was a problem hiding this comment.
I added new commit to handle error code while initializing ml agent.
Handle exception when initializing service-db instance. Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
0183218 to
9e67044
Compare
Clearly handle error code when initializing mlops-agent daemon. Signed-off-by: Jaeyun Jung <jy1210.jung@samsung.com>
d8945bb to
62ccd26
Compare
Handle exception when initializing service-db instance.