Problem with SDL

This is a discussion on Problem with SDL within the Game Programming forums, part of the General Programming Boards category; Its causing me memory leaks. In lines 13-40. I have no idea whats causing this so I would like someone ...

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    1

    Problem with SDL

    Its causing me memory leaks. In lines 13-40. I have no idea whats causing this so I would like someone to look at it for me.

    Thanks allready in advance.

    http://nopaste.php-q.net/226119

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,417
    > char *convert = (char*)malloc(10);
    > delete convert;
    1. Make your mind up as to whether this is C or C++.
    Use malloc + free or new + delete.
    Never mix the two.

    In particular, if you do
    char *convert = new char[10];
    Then you MUST do
    delete [ ] convert; // Yes, the [ ] are important.

    Also, 10 characters is woefully inadequate
    > sprintf(convert, "Damage %d-%d", player_mindamage, player_maxdamage);
    The fixed characters account for 8 chars, and then allowing for the \0, leaves only ONE char for BOTH integers.
    Instant buffer overflow.

    You may as well just declare
    char convert[100];
    and save yourself a whole bunch of memory management problems.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. SDL Performance problem
    By cboard_member in forum Game Programming
    Replies: 8
    Last Post: 04-09-2006, 01:23 PM
  2. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 05:24 PM
  3. SDL problem
    By ElastoManiac in forum Game Programming
    Replies: 11
    Last Post: 01-11-2006, 01:45 AM
  4. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 04:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21