author | erik <erik> | 2007-01-26 20:18:07 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-26 20:18:07 (UTC) |
commit | 152a8fe978851aea8dac6ae5cb11f73540746b83 (patch) (unidiff) | |
tree | 60f2fc2eb9a711e9aab91b9d743fd3730d5642e7 | |
parent | 644780047090442429342addb3fa97ec95bdc670 (diff) | |
download | opie-152a8fe978851aea8dac6ae5cb11f73540746b83.zip opie-152a8fe978851aea8dac6ae5cb11f73540746b83.tar.gz opie-152a8fe978851aea8dac6ae5cb11f73540746b83.tar.bz2 |
Both files in this commit exhibit use after free errors.
One of them was introduced in my memory leak fixing (whoops). I was freeing
a structure of stock data before one last call to it. So switching the free
to after that call fixed it.
The kcheckers.cpp fix is one where the game board could be deleted and then
a new one is not created because someone attempted to request a game board
type that is not supported. This is fixed by using the default directive for
one of the game board types in the switch statement. Which means it could
default to Russian boards. Score one for the Russians!
-rw-r--r-- | noncore/games/kcheckers/kcheckers.cpp | 1 | ||||
-rw-r--r-- | noncore/todayplugins/stockticker/libstocks/currency.c | 7 |
2 files changed, 4 insertions, 4 deletions
diff --git a/noncore/games/kcheckers/kcheckers.cpp b/noncore/games/kcheckers/kcheckers.cpp index a27dd18..433c68f 100644 --- a/noncore/games/kcheckers/kcheckers.cpp +++ b/noncore/games/kcheckers/kcheckers.cpp | |||
@@ -369,128 +369,129 @@ void KCheckers::drawBoard(int i) | |||
369 | } | 369 | } |
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
373 | void KCheckers::help() | 373 | void KCheckers::help() |
374 | { | 374 | { |
375 | QMessageBox::information(this,"Rules of Play", | 375 | QMessageBox::information(this,"Rules of Play", |
376 | "In the beginning of game you have\n" | 376 | "In the beginning of game you have\n" |
377 | "12 checkers (men).\n" | 377 | "12 checkers (men).\n" |
378 | "The men move forward only.\n" | 378 | "The men move forward only.\n" |
379 | "The men can capture:\n" | 379 | "The men can capture:\n" |
380 | "- by jumping forward only (english\n" | 380 | "- by jumping forward only (english\n" |
381 | " rules);\n" | 381 | " rules);\n" |
382 | "- by jumping forward or backward\n" | 382 | "- by jumping forward or backward\n" |
383 | " (russian rules).\n" | 383 | " (russian rules).\n" |
384 | "A man which reaches the far side of\n" | 384 | "A man which reaches the far side of\n" |
385 | "the board becomes a king.\n" | 385 | "the board becomes a king.\n" |
386 | "The kings move forward or\n" | 386 | "The kings move forward or\n" |
387 | "backward:\n" | 387 | "backward:\n" |
388 | "- to one square only (english rules);\n" | 388 | "- to one square only (english rules);\n" |
389 | "- to any number of squares (russian\n" | 389 | "- to any number of squares (russian\n" |
390 | " rules).\n" | 390 | " rules).\n" |
391 | "The kings capture by jumping\n" | 391 | "The kings capture by jumping\n" |
392 | "forward or backward.\n" | 392 | "forward or backward.\n" |
393 | "Whenever a player is able to make a\n" | 393 | "Whenever a player is able to make a\n" |
394 | "capture he must do so.", | 394 | "capture he must do so.", |
395 | QMessageBox::Ok|QMessageBox::Default); | 395 | QMessageBox::Ok|QMessageBox::Default); |
396 | } | 396 | } |
397 | 397 | ||
398 | 398 | ||
399 | void KCheckers::about() | 399 | void KCheckers::about() |
400 | { | 400 | { |
401 | QMessageBox::about(this,"About KCheckers", | 401 | QMessageBox::about(this,"About KCheckers", |
402 | "KCheckers, a board game. Ver 0.3\n" | 402 | "KCheckers, a board game. Ver 0.3\n" |
403 | "(C) 2002, A. Peredri <andi@ukr.net>\n\n" | 403 | "(C) 2002, A. Peredri <andi@ukr.net>\n\n" |
404 | "http://kcheckers.tuxfamily.org\n\n" | 404 | "http://kcheckers.tuxfamily.org\n\n" |
405 | "Contributors:\n" | 405 | "Contributors:\n" |
406 | "S. Rosen <srosen@erols.com>\n\n" | 406 | "S. Rosen <srosen@erols.com>\n\n" |
407 | "Qtopia version: S.Prud'homme\n" | 407 | "Qtopia version: S.Prud'homme\n" |
408 | "<prudhomme@laposte.net>\n\n" | 408 | "<prudhomme@laposte.net>\n\n" |
409 | "This program is distributed under the\n" | 409 | "This program is distributed under the\n" |
410 | "terms of the GNU General Public\n" | 410 | "terms of the GNU General Public\n" |
411 | "License."); | 411 | "License."); |
412 | } | 412 | } |
413 | 413 | ||
414 | 414 | ||
415 | void KCheckers::aboutQt() | 415 | void KCheckers::aboutQt() |
416 | { | 416 | { |
417 | QMessageBox::aboutQt(this); | 417 | QMessageBox::aboutQt(this); |
418 | } | 418 | } |
419 | 419 | ||
420 | 420 | ||
421 | void KCheckers::newGame() | 421 | void KCheckers::newGame() |
422 | { | 422 | { |
423 | if(game) delete game; | 423 | if(game) delete game; |
424 | 424 | ||
425 | switch(rules) | 425 | switch(rules) |
426 | { | 426 | { |
427 | case ENGLISH: | 427 | case ENGLISH: |
428 | game=new ECheckers(skill); | 428 | game=new ECheckers(skill); |
429 | CHECK_PTR(game); | 429 | CHECK_PTR(game); |
430 | break; | 430 | break; |
431 | 431 | ||
432 | case RUSSIAN: | 432 | case RUSSIAN: |
433 | default: | ||
433 | game=new RCheckers(skill); | 434 | game=new RCheckers(skill); |
434 | CHECK_PTR(game); | 435 | CHECK_PTR(game); |
435 | } | 436 | } |
436 | 437 | ||
437 | unselect(); | 438 | unselect(); |
438 | gameOver=false; | 439 | gameOver=false; |
439 | 440 | ||
440 | gameMenu->setItemEnabled(undoID,false); | 441 | gameMenu->setItemEnabled(undoID,false); |
441 | undoButton->setEnabled(false); | 442 | undoButton->setEnabled(false); |
442 | 443 | ||
443 | colorChange(); | 444 | colorChange(); |
444 | 445 | ||
445 | for(int i=0;i<32;i++) drawBoard(i); | 446 | for(int i=0;i<32;i++) drawBoard(i); |
446 | if(optionsMenu->isItemChecked(numID)) drawNumeration(); | 447 | if(optionsMenu->isItemChecked(numID)) drawNumeration(); |
447 | 448 | ||
448 | if(!userFirst) compGo(); | 449 | if(!userFirst) compGo(); |
449 | 450 | ||
450 | statusLabel->setText(tr("Go!")); | 451 | statusLabel->setText(tr("Go!")); |
451 | } | 452 | } |
452 | 453 | ||
453 | 454 | ||
454 | // Undo the last computer and user moves | 455 | // Undo the last computer and user moves |
455 | 456 | ||
456 | void KCheckers::undoMove() | 457 | void KCheckers::undoMove() |
457 | { | 458 | { |
458 | for(int i=0;i<32;i++) | 459 | for(int i=0;i<32;i++) |
459 | { | 460 | { |
460 | game->board[t[i]]=undoBoard[i]; | 461 | game->board[t[i]]=undoBoard[i]; |
461 | drawBoard(i); | 462 | drawBoard(i); |
462 | } | 463 | } |
463 | 464 | ||
464 | unselect(); | 465 | unselect(); |
465 | gameOver=false; | 466 | gameOver=false; |
466 | 467 | ||
467 | gameMenu->setItemEnabled(undoID,false); | 468 | gameMenu->setItemEnabled(undoID,false); |
468 | undoButton->setEnabled(false); | 469 | undoButton->setEnabled(false); |
469 | 470 | ||
470 | statusLabel->setText(tr("Go!")); | 471 | statusLabel->setText(tr("Go!")); |
471 | } | 472 | } |
472 | 473 | ||
473 | 474 | ||
474 | void KCheckers::colorChange() | 475 | void KCheckers::colorChange() |
475 | { | 476 | { |
476 | userFirst=!userFirst; | 477 | userFirst=!userFirst; |
477 | 478 | ||
478 | QImage* image; | 479 | QImage* image; |
479 | image=imageMan1; | 480 | image=imageMan1; |
480 | imageMan1=imageMan2; | 481 | imageMan1=imageMan2; |
481 | imageMan2=image; | 482 | imageMan2=image; |
482 | image=imageKing1; | 483 | image=imageKing1; |
483 | imageKing1=imageKing2; | 484 | imageKing1=imageKing2; |
484 | imageKing2=image; | 485 | imageKing2=image; |
485 | } | 486 | } |
486 | 487 | ||
487 | 488 | ||
488 | void KCheckers::unselect() | 489 | void KCheckers::unselect() |
489 | { | 490 | { |
490 | if(selected) field[from]->setFrame(NULL); | 491 | if(selected) field[from]->setFrame(NULL); |
491 | selected=false; | 492 | selected=false; |
492 | } | 493 | } |
493 | 494 | ||
494 | 495 | ||
495 | void KCheckers::click(int fieldNumber) | 496 | void KCheckers::click(int fieldNumber) |
496 | { | 497 | { |
diff --git a/noncore/todayplugins/stockticker/libstocks/currency.c b/noncore/todayplugins/stockticker/libstocks/currency.c index e0090e2..82cd654 100644 --- a/noncore/todayplugins/stockticker/libstocks/currency.c +++ b/noncore/todayplugins/stockticker/libstocks/currency.c | |||
@@ -1,67 +1,66 @@ | |||
1 | /* libstocks - Library to get current stock quotes from Yahoo Finance | 1 | /* libstocks - Library to get current stock quotes from Yahoo Finance |
2 | * | 2 | * |
3 | * Copyright (C) 2000 Eric Laeuffer | 3 | * Copyright (C) 2000 Eric Laeuffer |
4 | * | 4 | * |
5 | * This library is free software; you can redistribute it and/or | 5 | * This library is free software; you can redistribute it and/or |
6 | * modify it under the terms of the GNU Library General Public | 6 | * modify it under the terms of the GNU Library General Public |
7 | * License as published by the Free Software Foundation; either | 7 | * License as published by the Free Software Foundation; either |
8 | * version 2 of the License, or (at your option) any later version. | 8 | * version 2 of the License, or (at your option) any later version. |
9 | * | 9 | * |
10 | * This library is distributed in the hope that it will be useful, | 10 | * This library is distributed in the hope that it will be useful, |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | * Library General Public License for more details. | 13 | * Library General Public License for more details. |
14 | * | 14 | * |
15 | * You should have received a copy of the GNU Library General Public | 15 | * You should have received a copy of the GNU Library General Public |
16 | * License along with this library; if not, write to the | 16 | * License along with this library; if not, write to the |
17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 17 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18 | * Boston, MA 02111-1307, USA. | 18 | * Boston, MA 02111-1307, USA. |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #define __CURRENCY_C__ | 21 | #define __CURRENCY_C__ |
22 | 22 | ||
23 | 23 | ||
24 | #include <stdio.h> | 24 | #include <stdio.h> |
25 | #include <string.h> | 25 | #include <string.h> |
26 | #include <malloc.h> | 26 | #include <malloc.h> |
27 | #include <stdlib.h> | 27 | #include <stdlib.h> |
28 | 28 | ||
29 | #include "stocks.h" | 29 | #include "stocks.h" |
30 | 30 | ||
31 | /*****************************************************************************/ | 31 | /*****************************************************************************/ |
32 | /* returns the currency exchange rate of "from" currency into */ | 32 | /* returns the currency exchange rate of "from" currency into */ |
33 | /* "into" currency. */ | 33 | /* "into" currency. */ |
34 | /*****************************************************************************/ | 34 | /*****************************************************************************/ |
35 | libstocks_return_code get_currency_exchange(char *from, | 35 | libstocks_return_code get_currency_exchange(char *from, |
36 | char *into, | 36 | char *into, |
37 | float *exchange) | 37 | float *exchange) |
38 | { | 38 | { |
39 | char *symbol; | 39 | char *symbol; |
40 | stock *data; | 40 | stock *data; |
41 | libstocks_return_code error; | 41 | libstocks_return_code error; |
42 | 42 | ||
43 | if((symbol = (char *)malloc(strlen(from)+strlen(into)+3))==NULL) | 43 | if((symbol = (char *)malloc(strlen(from)+strlen(into)+3))==NULL) |
44 | { | 44 | { |
45 | fprintf(stderr,"Memory allocating error (%s line %d)\n" | 45 | fprintf(stderr,"Memory allocating error (%s line %d)\n" |
46 | ,__FILE__, __LINE__); | 46 | ,__FILE__, __LINE__); |
47 | exit(1); | 47 | exit(1); |
48 | } | 48 | } |
49 | 49 | ||
50 | strcpy(symbol, from); | 50 | strcpy(symbol, from); |
51 | strcat(symbol, into); | 51 | strcat(symbol, into); |
52 | strcat(symbol, "=X"); | 52 | strcat(symbol, "=X"); |
53 | 53 | ||
54 | error = get_stocks(symbol, &data); | 54 | error = get_stocks(symbol, &data); |
55 | free(symbol); | 55 | free(symbol); |
56 | if (error) | 56 | if (error) |
57 | { | 57 | { |
58 | *exchange = 0; | 58 | *exchange = 0; |
59 | return(error); | 59 | return error; |
60 | } | 60 | } |
61 | 61 | ||
62 | free_stocks(data); | ||
63 | |||
64 | *exchange = data->CurrentPrice; | 62 | *exchange = data->CurrentPrice; |
65 | return(error); | 63 | free_stocks(data); |
64 | return error; | ||
66 | 65 | ||
67 | } | 66 | } |