Skip to content

Commit

Permalink
Merge pull request #241 from chewing/fix-g-free
Browse files Browse the repository at this point in the history
fix: free chewing objects with chewing_free
  • Loading branch information
kanru authored Dec 7, 2024
2 parents 7824ae6 + 9682680 commit 1bb323d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
17 changes: 6 additions & 11 deletions src/IBusChewingLookupTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@ IBusLookupTable *ibus_chewing_lookup_table_new(ChewingContext *context) {
guint size = 10;
gboolean cursorShow = TRUE;
gboolean wrapAround = TRUE;
IBusLookupTable *iTable =
ibus_lookup_table_new(size, 0, cursorShow, wrapAround);
IBusLookupTable *iTable = ibus_lookup_table_new(size, 0, cursorShow, wrapAround);

ibus_chewing_lookup_table_resize(iTable, context);

return iTable;
}

void ibus_chewing_lookup_table_resize(IBusLookupTable *iTable,
ChewingContext *context) {
void ibus_chewing_lookup_table_resize(IBusLookupTable *iTable, ChewingContext *context) {
gint selKSym[MAX_SELKEY];
g_autoptr(GSettings) settings = g_settings_new(QUOTE_ME(PROJECT_SCHEMA_ID));
g_autofree char *selKeyStr = g_settings_get_string(settings, "sel-keys");
Expand All @@ -34,23 +32,20 @@ void ibus_chewing_lookup_table_resize(IBusLookupTable *iTable,
for (i = 0; i < len; i++) {
selKSym[i] = (gint)selKeyStr[i];

iText = g_object_ref_sink(
ibus_text_new_from_printf("%c.", toupper(selKeyStr[i])));
iText = g_object_ref_sink(ibus_text_new_from_printf("%c.", toupper(selKeyStr[i])));
ibus_lookup_table_set_label(iTable, i, iText);
g_object_unref(iText);
}
}
chewing_set_candPerPage(context, len);
chewing_set_selKey(context, selKSym, len);

gboolean verticalLookupTable =
g_settings_get_boolean(settings, "vertical-lookup-table");
gboolean verticalLookupTable = g_settings_get_boolean(settings, "vertical-lookup-table");

ibus_lookup_table_set_orientation(iTable, verticalLookupTable);
}

guint ibus_chewing_lookup_table_update(IBusLookupTable *iTable,
ChewingContext *context) {
guint ibus_chewing_lookup_table_update(IBusLookupTable *iTable, ChewingContext *context) {
IBusText *iText = NULL;
gint i;
gint choicePerPage = chewing_cand_ChoicePerPage(context);
Expand All @@ -70,7 +65,7 @@ guint ibus_chewing_lookup_table_update(IBusLookupTable *iTable,

iText = g_object_ref_sink(ibus_text_new_from_string(candidate));
ibus_lookup_table_append_candidate(iTable, iText);
g_free(candidate);
chewing_free(candidate);
g_object_unref(iText);
} else {
break;
Expand Down
3 changes: 2 additions & 1 deletion src/IBusChewingPreEdit.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void ibus_chewing_pre_edit_free(IBusChewingPreEdit *self) {
}

gchar *ibus_chewing_pre_edit_get_bopomofo_string(IBusChewingPreEdit *self) {
// FIXME: libchewing should provide chewing_bopomofo_String(ctx)
const gchar *buf = chewing_bopomofo_String_static(self->context);

return g_strdup(buf);
Expand Down Expand Up @@ -94,7 +95,7 @@ void ibus_chewing_pre_edit_update(IBusChewingPreEdit *self) {

self->wordLen = i + self->bpmfLen;

g_free(bufferStr);
chewing_free(bufferStr);
g_free(bpmfStr);

ibus_chewing_pre_edit_update_outgoing(self);
Expand Down
4 changes: 2 additions & 2 deletions src/ibus-chewing-engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ void refresh_aux_text(IBusChewingEngine *self) {

IBUS_CHEWING_LOG(INFO, "update_aux_text() auxStr=%s", auxStr);
self->auxText = g_object_ref_sink(ibus_text_new_from_string(auxStr));
g_free(auxStr);
chewing_free(auxStr);
} else if (self->prop_notify_mode_change && self->pending_notify_chinese_english_mode) {
self->pending_notify_chinese_english_mode = FALSE;
char *auxStr = is_chinese_mode(self) ? _("Chinese Mode") : _("English Mode");
Expand Down Expand Up @@ -1073,7 +1073,7 @@ void ibus_chewing_engine_candidate_clicked(IBusEngine *engine, guint index, guin
KSym k = (KSym)selKeys[index];

ibus_chewing_pre_edit_process_key(self->icPreEdit, k, 0);
g_free(selKeys);
chewing_free(selKeys);
ibus_chewing_engine_update(self);
} else {
IBUS_CHEWING_LOG(DEBUG, "candidate_clicked() ... candidates are not showing");
Expand Down

0 comments on commit 1bb323d

Please sign in to comment.