summaryrefslogtreecommitdiff
path: root/src/lib/ecore_win32
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2020-02-25 10:27:14 -0500
committerMike Blumenkrantz <zmike@samsung.com>2020-02-25 10:27:16 -0500
commitfa562828b8d08fa4e6902b061e8bb8bda430b8a7 (patch)
tree07ec7b43cdcdacd15573e6a2c5f9216a113a0689 /src/lib/ecore_win32
parent0ff7469d91df09f859dffd5152dfc508759206e6 (diff)
Ecore_Win32: free 'compose' field when needed, fix memory leak
Reviewers: raster, zmike Reviewed By: zmike Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D11415
Diffstat (limited to 'src/lib/ecore_win32')
-rw-r--r--src/lib/ecore_win32/ecore_win32_event.c47
1 files changed, 32 insertions, 15 deletions
diff --git a/src/lib/ecore_win32/ecore_win32_event.c b/src/lib/ecore_win32/ecore_win32_event.c
index c2e9200580..0c232e7bc3 100644
--- a/src/lib/ecore_win32/ecore_win32_event.c
+++ b/src/lib/ecore_win32/ecore_win32_event.c
@@ -273,7 +273,8 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
273 char string[2] = { 0, 0 }; 273 char string[2] = { 0, 0 };
274 const char *keyname = NULL; 274 const char *keyname = NULL;
275 const char *key = NULL; 275 const char *key = NULL;
276 const char *compose = NULL; 276 char *compose = NULL;
277 unsigned char free_compose = 0;
277 278
278 switch (msg->window_param) 279 switch (msg->window_param)
279 { 280 {
@@ -1178,12 +1179,16 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1178 { 1179 {
1179 /* dead key, but managed like normal key */ 1180 /* dead key, but managed like normal key */
1180 compose = evil_utf16_to_utf8(buf); 1181 compose = evil_utf16_to_utf8(buf);
1182 free_compose = 1;
1181 } 1183 }
1182 else if (res == 0) 1184 else if (res == 0)
1183 { 1185 {
1184 INF("No translatable character found, skipping"); 1186 INF("No translatable character found, skipping");
1185 if (msg->window_param >= 0x30 && msg->window_param <= 0x39) 1187 if (msg->window_param >= 0x30 && msg->window_param <= 0x39)
1186 compose = evil_utf16_to_utf8(buf); 1188 {
1189 compose = evil_utf16_to_utf8(buf);
1190 free_compose = 1;
1191 }
1187 /* otherwise, compose is NULL */ 1192 /* otherwise, compose is NULL */
1188 } 1193 }
1189 else if (res >= 2) 1194 else if (res >= 2)
@@ -1197,11 +1202,17 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1197 MapVirtualKey(msg->window_param, MAPVK_VK_TO_CHAR), 1202 MapVirtualKey(msg->window_param, MAPVK_VK_TO_CHAR),
1198 kbd_state, buf, 4, 0); 1203 kbd_state, buf, 4, 0);
1199 if (!((res != 1) && (res != -1))) 1204 if (!((res != 1) && (res != -1)))
1200 compose = evil_utf16_to_utf8(buf); 1205 {
1206 compose = evil_utf16_to_utf8(buf);
1207 free_compose = 1;
1208 }
1201 /* otherwise, compose is NULL */ 1209 /* otherwise, compose is NULL */
1202 } 1210 }
1203 else /* res == 1 : 1 char written to buf */ 1211 else /* res == 1 : 1 char written to buf */
1204 compose = evil_utf16_to_utf8(buf); 1212 {
1213 compose = evil_utf16_to_utf8(buf);
1214 free_compose = 1;
1215 }
1205 1216
1206 /*** key field ***/ 1217 /*** key field ***/
1207 1218
@@ -1214,7 +1225,7 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1214 _ecore_win32_modifiers_ctrl_save(kbd_state, &modifiers_save); 1225 _ecore_win32_modifiers_ctrl_save(kbd_state, &modifiers_save);
1215 1226
1216 if (!SetKeyboardState(kbd_state)) 1227 if (!SetKeyboardState(kbd_state))
1217 return NULL; 1228 goto _free_compose;
1218 } 1229 }
1219 1230
1220 is_dead_key = EINA_FALSE; 1231 is_dead_key = EINA_FALSE;
@@ -1246,7 +1257,7 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1246 if (res == -1) 1257 if (res == -1)
1247 is_dead_key = EINA_TRUE; 1258 is_dead_key = EINA_TRUE;
1248 if ((res != 1) && (res != -1)) 1259 if ((res != 1) && (res != -1))
1249 return NULL; 1260 goto _free_compose;
1250 } 1261 }
1251 1262
1252 if (is_dead_key) 1263 if (is_dead_key)
@@ -1264,13 +1275,13 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1264 _ecore_win32_modifiers_ctrl_restore(kbd_state, modifiers_save); 1275 _ecore_win32_modifiers_ctrl_restore(kbd_state, modifiers_save);
1265 1276
1266 if (!SetKeyboardState(kbd_state)) 1277 if (!SetKeyboardState(kbd_state))
1267 return NULL; 1278 goto _free_compose;
1268 } 1279 }
1269 1280
1270 if (!key) 1281 if (!key)
1271 { 1282 {
1272 WRN("no keysym found for keycode %d\n", string[0]); 1283 WRN("no keysym found for keycode %d\n", string[0]);
1273 return NULL; 1284 goto _free_compose;
1274 } 1285 }
1275 1286
1276 /*** keyname field ***/ 1287 /*** keyname field ***/
@@ -1284,7 +1295,7 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1284 _ecore_win32_modifiers_win_save(kbd_state, &modifiers_save); 1295 _ecore_win32_modifiers_win_save(kbd_state, &modifiers_save);
1285 1296
1286 if (!SetKeyboardState(kbd_state)) 1297 if (!SetKeyboardState(kbd_state))
1287 return NULL; 1298 goto _free_compose;
1288 1299
1289 is_dead_key = EINA_FALSE; 1300 is_dead_key = EINA_FALSE;
1290 res = ToUnicode(msg->window_param, 1301 res = ToUnicode(msg->window_param,
@@ -1317,7 +1328,7 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1317 if (res == -1) 1328 if (res == -1)
1318 is_dead_key = EINA_TRUE; 1329 is_dead_key = EINA_TRUE;
1319 if ((res != 1) && (res != -1)) 1330 if ((res != 1) && (res != -1))
1320 return NULL; 1331 goto _free_compose;
1321 } 1332 }
1322 1333
1323 if (is_dead_key) 1334 if (is_dead_key)
@@ -1336,25 +1347,25 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1336 _ecore_win32_modifiers_win_restore(kbd_state, modifiers_save); 1347 _ecore_win32_modifiers_win_restore(kbd_state, modifiers_save);
1337 1348
1338 if (!SetKeyboardState(kbd_state)) 1349 if (!SetKeyboardState(kbd_state))
1339 return NULL; 1350 goto _free_compose;
1340 1351
1341 if (!keyname) 1352 if (!keyname)
1342 { 1353 {
1343 WRN("no keysym found for keycode %d\n", string[0]); 1354 WRN("no keysym found for keycode %d\n", string[0]);
1344 return NULL; 1355 goto _free_compose;
1345 } 1356 }
1346 } 1357 }
1347 } 1358 }
1348 1359
1349 if (!keyname || !key) 1360 if (!keyname || !key)
1350 return NULL; 1361 goto _free_compose;
1351 1362
1352 e = (Ecore_Event_Key *)calloc(1, sizeof(Ecore_Event_Key) + 1363 e = (Ecore_Event_Key *)calloc(1, sizeof(Ecore_Event_Key) +
1353 strlen(keyname) + 1 + 1364 strlen(keyname) + 1 +
1354 strlen(key) + 1 + 1365 strlen(key) + 1 +
1355 (compose ? strlen(compose) : 0) + 1); 1366 (compose ? strlen(compose) : 0) + 1);
1356 if (!e) 1367 if (!e)
1357 return NULL; 1368 goto _free_compose;
1358 1369
1359 e->keyname = (char *)(e + 1); 1370 e->keyname = (char *)(e + 1);
1360 e->key = e->keyname + strlen(keyname) + 1; 1371 e->key = e->keyname + strlen(keyname) + 1;
@@ -1368,11 +1379,17 @@ _ecore_win32_event_keystroke_get(Ecore_Win32_Callback_Data *msg,
1368 if (compose) 1379 if (compose)
1369 { 1380 {
1370 memcpy((char *)e->compose, compose, strlen(compose)); 1381 memcpy((char *)e->compose, compose, strlen(compose));
1371 free(compose); 1382 if (free_compose)
1383 free(compose);
1372 } 1384 }
1373 1385
1374 1386
1375 return e; 1387 return e;
1388
1389 _free_compose:
1390 if (free_compose)
1391 free(compose);
1392 return NULL;
1376} 1393}
1377 1394
1378/***** Global functions definitions *****/ 1395/***** Global functions definitions *****/