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
Printable View
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
> 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.