mirror of
https://gitee.com/milvus-io/milvus.git
synced 2026-01-07 19:31:51 +08:00
fix: Avoided dereferencing NULL pointer (#34836)
issue : https://github.com/milvus-io/milvus/issues/34835 Signed-off-by: Ald392 <imagesai32@gmail.com>
This commit is contained in:
parent
804ec24c02
commit
9463eeef2b
@ -10,7 +10,9 @@
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
#include <string.h>
|
||||
#include "common/EasyAssert.h"
|
||||
#include "config/ConfigKnowhere.h"
|
||||
#include "fmt/core.h"
|
||||
#include "indexbuilder/init_c.h"
|
||||
|
||||
void
|
||||
@ -23,6 +25,7 @@ char*
|
||||
IndexBuilderSetSimdType(const char* value) {
|
||||
auto real_type = milvus::config::KnowhereSetSimdType(value);
|
||||
char* ret = reinterpret_cast<char*>(malloc(real_type.length() + 1));
|
||||
AssertInfo(ret != nullptr, "memmory allocation for ret failed!");
|
||||
memcpy(ret, real_type.c_str(), real_type.length());
|
||||
ret[real_type.length()] = 0;
|
||||
return ret;
|
||||
|
||||
@ -14,6 +14,8 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "common/EasyAssert.h"
|
||||
#include "fmt/core.h"
|
||||
#include "log/Log.h"
|
||||
|
||||
/*
|
||||
@ -105,6 +107,7 @@ get_thread_starttime() {
|
||||
int64_t val = 0;
|
||||
char comm[16], state;
|
||||
FILE* thread_stat = fopen(filename, "r");
|
||||
AssertInfo(thread_stat != nullptr, "opening file:{} failed!", filename);
|
||||
auto ret = fscanf(
|
||||
thread_stat, "%lld %s %s ", (long long*)&val, comm, &state); // NOLINT
|
||||
|
||||
|
||||
@ -11,6 +11,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "common/EasyAssert.h"
|
||||
#include "fmt/core.h"
|
||||
#include "knowhere/prometheus_client.h"
|
||||
#include "segcore/metrics_c.h"
|
||||
|
||||
@ -19,6 +21,7 @@ GetKnowhereMetrics() {
|
||||
auto str = knowhere::prometheusClient->GetMetrics();
|
||||
auto len = str.length();
|
||||
char* res = (char*)malloc(len + 1);
|
||||
AssertInfo(res != nullptr, "memmory allocation for res failed!");
|
||||
memcpy(res, str.data(), len);
|
||||
res[len] = '\0';
|
||||
return res;
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
// or implied. See the License for the specific language governing permissions and limitations under the License
|
||||
|
||||
#include "config/ConfigKnowhere.h"
|
||||
#include "fmt/core.h"
|
||||
#include "log/Log.h"
|
||||
#include "segcore/SegcoreConfig.h"
|
||||
#include "segcore/segcore_init_c.h"
|
||||
@ -74,6 +75,7 @@ SegcoreSetSimdType(const char* value) {
|
||||
LOG_DEBUG("set config simd_type: {}", value);
|
||||
auto real_type = milvus::config::KnowhereSetSimdType(value);
|
||||
char* ret = reinterpret_cast<char*>(malloc(real_type.length() + 1));
|
||||
AssertInfo(ret != nullptr, "memmory allocation for ret failed!");
|
||||
memcpy(ret, real_type.c_str(), real_type.length());
|
||||
ret[real_type.length()] = 0;
|
||||
return ret;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user