try to fix memory leak.
This commit is contained in:
parent
7b55d3ff9c
commit
d831b7626b
@ -97,11 +97,13 @@ static Wikidiff2::String char_to_string(char* cstr){
|
||||
return str;
|
||||
}
|
||||
|
||||
static Wikidiff2::String wikidiff2_inline_json_diff(pywikidiff2Obj *self, Wikidiff2::String text1String, Wikidiff2::String text2String){
|
||||
Wikidiff2 wikidiff2( *(&self->config));
|
||||
static Wikidiff2::String wikidiff2_inline_json_diff(pywikidiff2Obj *self, char* text1, char* text2){
|
||||
Wikidiff2::String str1(text1, strlen(text1));
|
||||
Wikidiff2::String str2(text2, strlen(text2));
|
||||
Wikidiff2 wikidiff2( *(&self->config));
|
||||
InlineJSONFormatter formatter;
|
||||
wikidiff2.addFormatter(formatter);
|
||||
wikidiff2.execute(text1String, text2String);
|
||||
wikidiff2.execute(str1, str2);
|
||||
Wikidiff2::String ret = formatter.getResult().str();
|
||||
return ret;
|
||||
}
|
||||
@ -155,11 +157,32 @@ static PyObject *pywikidiff2_inline_json_diff_sequence(pywikidiff2Obj *self, PyO
|
||||
}
|
||||
PyObject *result_list;
|
||||
result_list = PyList_New(list_size);
|
||||
char* last_text;
|
||||
char* text;
|
||||
size_t last_text_len;
|
||||
size_t text_len;
|
||||
for(i = 1; i<list_size+1; ++i){
|
||||
Wikidiff2::String diff_str = wikidiff2_inline_json_diff(self, input_texts_str[i-1], input_texts_str[i]);
|
||||
if(i == 1){
|
||||
last_text_len = strlen(input_texts_str[i-1]);
|
||||
text_len = strlen(input_texts_str[i]);
|
||||
last_text = new char[last_text_len];
|
||||
text = new char[text_len];
|
||||
strcpy(last_text, input_texts_str[i-1]);
|
||||
strcpy(text, input_texts_str[i]);
|
||||
} else {
|
||||
delete last_text;
|
||||
last_text = text;
|
||||
last_text_len = text_len;
|
||||
text_len = strlen(input_texts_str[i]);
|
||||
text = new char[text_len];
|
||||
strcpy(text, input_texts_str[i]);
|
||||
}
|
||||
Wikidiff2::String diff_str = wikidiff2_inline_json_diff(self, last_text, text);
|
||||
PyObject* py_diff = PyUnicode_FromFormat("%s",diff_str.c_str());
|
||||
PyList_SetItem(result_list, i-1, py_diff);
|
||||
}
|
||||
delete last_text;
|
||||
delete text;
|
||||
return result_list;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user