Skip to content

Commit 3fa1c6f

Browse files
Added proper exception handling to avoid segfault if the model path is wrong
1 parent 78cebcf commit 3fa1c6f

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

src/sam_inference.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,9 @@ const char* SAM::CreateSession(SEG::DL_INIT_PARAM& iParams)
118118
}
119119
catch (const std::exception& e)
120120
{
121-
const char* str1 = "[SAM]: ";
122-
const char* str2 = e.what();
123-
std::string str_result = std::string(str1) + std::string(str2);
124-
char* merged = new char[str_result.length() + 1];
125-
std::strcpy(merged, str_result.c_str());
126-
CONSOLE_BRIDGE_logWarn("%s", merged);
127-
delete[] merged;
128-
return "[SAM]: CreateSession failed.";
121+
std::string error_msg = "[SAM]: Failed to create session: " + std::string(e.what());
122+
CONSOLE_BRIDGE_logWarn("%s", error_msg.c_str());
123+
throw std::runtime_error(error_msg);
129124
}
130125
}
131126

0 commit comments

Comments
 (0)