Skip to content

Commit 2e84090

Browse files
Copilotwannaphong
andcommitted
Fix error handling for strdup() and add missing include
Co-authored-by: wannaphong <8536487+wannaphong@users.noreply.github.com>
1 parent 5c951c5 commit 2e84090

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

python/cthainlp_wrapper.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define PY_SSIZE_T_CLEAN
77
#include <Python.h>
88
#include <string.h>
9+
#include <stdlib.h>
910
#include "newmm.h"
1011

1112
/* Module-level dictionary cache */
@@ -52,6 +53,12 @@ static newmm_dict_t get_or_load_dict(const char* dict_path) {
5253
dict_cache.dict = newmm_load_dict(dict_path);
5354
if (dict_cache.dict && dict_path) {
5455
dict_cache.dict_path = strdup(dict_path);
56+
if (!dict_cache.dict_path) {
57+
/* strdup failed, clean up and return NULL */
58+
newmm_free_dict(dict_cache.dict);
59+
dict_cache.dict = NULL;
60+
return NULL;
61+
}
5562
}
5663
}
5764

0 commit comments

Comments
 (0)