Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Memory Leak?  (Read 4879 times)

0 Members and 1 Guest are viewing this topic.

DaveLembke

    Topic Starter


    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Memory Leak?
« on: February 04, 2016, 08:53:24 AM »
Well I ran a test against my code to throw 1 Trillion keys at it to make sure that I would not have a key that when used would output the same characters as the input for a crypto program I have been playing with and building upon. The AMD-FX-8350 at 4000Mhz took 7 days to complete 1 Trillion key tests with string compares with each core crunching 125 Billion Key tests, but what caught my eye is that the system memory showed that only 260MB was free of 8GB DDR3 1600mhz RAM. When I started the program last week only about 1.5GB of 8GB was in use, and the system was offline just used to crunch the project that I threw at it with 8 programs running 12.5% of 1 Trillion keys each to make use of all cores as 8 individual threads.

Looking in task manager it showed that svchost.exe using 6GB of the 8GB and other services using up the other 1.6GB of RAM. Ran a virus scan against system even though I know that its clean, and it came up clean. Rebooted system for first time in a week and it went back to normal with a little over 1GB in use at idle and almost 7GB free.

Curious if this is a memory leak in my program that I wrote, but if a memory leak I would expect it to free up the memory upon exiting the 8 instances of the program that I wrote. In my program all variables are initialized and I am not using anything improper, although I do use some system calls, but I've used them for years without any problems. Only thing I did different in this program than others in past that I have written is add a display trip to show status at every millionth counter tick of display to show the counter value. I wanted to know where the programs were at with a progress indicator, but showing a constant print to display cripples performance heavily so with a single print to display of the status every 1 millionth tick, I was able to know where the programs were at and how far away from completion without crippling performance.

Just out of curiosity I made a copy of this program without the while loop millionth print status to print status for every iteration and compiled that and ran both of them together side by side and the program that constantly prints to display status was so incredibly slow than the one that showed only every millionth tick. I then laughed at how many movies you watch where they show a hacker hitting a security of some sort with a counter like program attack with scrolling digits or alpha of all the keys its trying super fast, and realized that the best one would be one that didnt print to display until a match was found. But that I guess would make for a boring few minutes of a movie whereas scrolling digits or alpha has the better visual effect.

Additionally although I wasted 7 days testing for an exact match between the starting string and the seeded random shuffle which didnt exist, but could have. It wasnt a waste because I made use of this test and implemented a test instruction into my main program to test for a match and reject use of a bad (WEAK) key. Additionally I also added a string compare instruction that instead of the user entering a key of their choice you can specify how strong of a shuffle you want, such as no characters would ever line up with their original character or allow a certain number of them to be the same with others far from their original form. This then spawned off the curiosity as to even if not a 85 for 85 character match, just how close of an exact match is there between the original string and the shuffled output string, and out of 85 possible characters, very few shuffles end up with more than 10 characters the same between the original string and the shuffled output. To compare for the original string and the output I am using a counter and comparing str[counter] against str2[counter] which performs a string compare from array to array for each element against each other of the same element location within array.


Code: [Select]
#include <iostream>
#include <string>


int delay;
long long int counter=0;
long long int endcount=0;
long long int match=0;
long long int nomatch=0;
long long int seed1=0;
int display=0;

int main ()
{
    std::cout<<"Enter Starting Value\n";
    std::cin>>counter;
    std::cout<<"\n"<<"Enter Ending Value\n";
    std::cin>>endcount;
    std::cout<<"\n\n";

    std::string str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+=?<>:\\/~.,;";
    std::string str2="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()_-+=?<>:\\/~.,;";
    system("@echo. Started on %date% at %time%>>Log1.txt");
    std::cout<<"Running Please Wait...\n";
    while(counter<=endcount){
                         
    seed1=counter;       
                         
    srand(seed1);
   
    random_shuffle(str.begin(), str.end()); // Shuffle the string

display++;

  if (str.compare(str2) != 0){

    while(display==1000000){
    std::cout<<"counter = "<<counter<<" \n";
    display=0;
}
    nomatch++;

}
  else{
       std::cout<<"counter= "<<counter<<"   -  Match Found\n";
       match++;
       std::cin>>delay;
       }
       counter++;
       }
       std::cout<<"Match    = "<<match<<"\n";
       std::cout<<"No Match = "<<nomatch<<"\n";
       system("@echo. Ended on %date% at %time%>>Log1.txt");
std::cin>>delay;
  return 0;
}

Allan

  • Moderator

  • Mastermind
  • Thanked: 1260
  • Experience: Guru
  • OS: Windows 10
Re: Memory Leak?
« Reply #1 on: February 04, 2016, 09:00:45 AM »
I think you have much too much time on your hands ;D ;D

BC_Programmer


    Mastermind
  • Typing is no substitute for thinking.
  • Thanked: 1140
    • Yes
    • Yes
    • BC-Programming.com
  • Certifications: List
  • Computer: Specs
  • Experience: Beginner
  • OS: Windows 11
Re: Memory Leak?
« Reply #2 on: February 04, 2016, 09:23:26 AM »
random_shuffle is undefined in the above sample; I had to add
Code: [Select]
#include <algorithm>
using namespace std;

Do you run systems for that long very often? If the system is running Windows 7 it could have fallen victim to a number of diagnosed problems such as this one, and is a memory leak related to Windows Update. If you don't tend to run your systems as long as you did to run this program you might not have considered it out of the ordinary.

If it was a memory leak I would expect it to be instantly obvious when running but it sat at a little over 800K private bytes the entire time I ran it.
I was trying to dereference Null Pointers before it was cool.

Geek-9pm


    Mastermind
  • Geek After Dark
  • Thanked: 1026
    • Gekk9pm bnlog
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Memory Leak?
« Reply #3 on: February 04, 2016, 09:58:04 AM »
I think you have much too much time on your hands ;D ;D

DaveLembke

    Topic Starter


    Sage
  • Thanked: 662
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Windows 10
Re: Memory Leak?
« Reply #4 on: February 04, 2016, 10:32:51 AM »
Yes this time of year I generally have too much time on my hands.   ;D   Every winter I generally dive into a project of some sort. I like programming, but there have been so many times that I have felt an urge to write a program of my own and its like, what can I make that isn't completely pointless and would be useful to me. Making a program that scrambles text became this winters project as for I have a small notebook that I use to keep in my trunk of my car so that in case of a fire or same notebook in home was lost, I'd still have passwords and private info readily available... BUT its very dangerous having it all in a small notebook where if it fell out of my trunk or someone got their hands on it they would have "EVERYTHING" in clear text to use.

 My plans with the program I have is its a 2 part. A file is created with a key listing, and another file is created with the scrambled data. The key file and scrambled data file are kept separate so its like a key and a lockbox. But the lockbox is like a box of scrabble squares in it with the squares all different colors. It could be any message, but without the key and program to reassemble the message its almost pointless. Then a USB stick or a CD or DVD is burned with this data only without the program and keys needed to decrypt it. The program and key file is then kept in 2 locations, but never in the trunk of car, where odds of both locations having a fire for example at same time to destroy it are unlikely and the data and the tool and key to decrypt it are always kept appart with exception to when I need to look up a complex password that I dont use every day.

The program I have now is not perfect and it needs to be strengthened. For now with it in its weak form words that have duplicate characters such as Hello World I enter into it as HeLlo World so that a duplicate character output is not seen in the scrambled output which is what a crypto cracker would probably use as a means to brute force it back to its original form. But passwords that are case sensitive unfortunately if there is a Password of YellowDog5$  the scrambled output would be something like &577*xH*+qU and that 77 pairing in there is a weakness!

Hoping to implement later more complexity to it so that you could get pairing but pairing would not likely ever be substitution for the same character by use of multiple shuffled strings in use and based on the character placement within the full message to crypt its scrambled that much more complexly. Including an idea to salt the message with extra characters to add noise to it so Hello_World would not be always a scrambled output of 11 characters, but could be greater than 11 characters such as an output of G6*k@mJ?>0pZ&$Bvd3L# ( 20 characters ).

The good thing is that my wife of 20 years knows my Winter Cycle of diving into programming heavily winters when daylight is short and too cold outside TV is boring and I get burnt out on video games. She has learned not to ask what I have been up to. Although she asked the other day and then after I started spilling out what i was doing and this algorithm doing this and the probability of a string match and running 1 Trillion iterations to test for the slim possibility of an exact match absolute worst key to use scenario she told me to shut up. ha ha ha  ;D   Then I had an idea and started writing it onto paper as a brain dump and she told me she doesnt want to see me even writing code or flow charts at the dinner table as my brain is still going.  ::) I told her as long as she doesnt see me wallpapering the room in source code and flow charts that I'm still sane.  :P

She also said you should have married a computer nerd girl who gets turned on by code talk. I then reminded her of a girl that matched well with me at work 16 years ago and how if I wasnt married to my wife, I suppose that would have been the one since we were both heavily flirting with geek speak and very into each others conversations, as well as she was very nice on the eyes, but being true to my wife, I didnt leave her or cheat. She just looked at me and shook her head and I laughed. I said so they say opposites attract. And your telling me that likes attract then.  :P She then said that you should have been a character on the tv show big bang theory and I laughed and said thank you for that compliment.  ;D

Thanks BC for that info on Windows 7 memory leak. I wasnt aware of that and this system hasnt been connected for Windows updates in a while. I will update it tonight. Also interesting that my IDE didnt complain about the #include <algorithm> missing, not even a warning in the compile log. Also I dont run systems for days on end anymore other than some laptops that are crunching for BOINC in my basement. I either shut down my systems or have them processing data that is CPU intensive such as online gaming events with others that i record with Fraps and then use virtual dub to take the raw 40GB video file and process it down to a more manageable 1GB video file when I am sleeping and they are completed with processing by the time I wake up in which I check e-mail, delete the massive 40GB file and then shut it down and head to work.