![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
|
Segmentation Fault!
I keep getting a Segmentation Fault in my program and I cannot figure it out. I don't have much experience with that sort of thing, so maybe you could give me some advice.
Here is the code that seems to be generating the segfault: BOOL PathExists(const char* pathtocheck)
{
struct stat St;
BOOL bRes = stat( pathtocheck, &St );
}
int IsInstalled(char *envPath, char *folderPath, int pathCheck)
{
char tempEnv[1024];
GetEnvironmentVariable(envPath, tempEnv, MAX_PATH);
strcat(tempEnv, folderPath);
// strcat(envPath, tempEnv);
// strcpy(fullPath, tempEnv);
if ( PathExists(tempEnv) == 0 )
pathCheck = 1;
// free(tempEnv);
// free(envPath);
// return pathCheck;
}I'm calling the functions here: case ID_IS_INSTALLED:
{
SendDlgItemMessage(hDlgWnd, IDC_DLG_TEXT, EM_REPLACESEL, FALSE, 0);
char buffer[MAX_PATH];
char fullPath[MAX_PATH];
char tempBuffer[1024];
int check, checkTwo, checkThree, checkFour,
checkFive, checkSix, checkSeven, checkEight,
checkNine, checkTen, checkEleven;
// HWND hwnd = GetDlgItem(hDlgWnd, IDC_DLG_TEXT);
check = IsInstalled("PROGRAMFILES", "\\Viewpoint\\Viewpoint Media Player", check);
checkTwo = IsInstalled("PROGRAMFILES", "\\Viewpoint\\Viewpoint Manager", checkTwo);
checkThree = IsInstalled("ALLUSERSPROFILE", "\\Viewpoint\\Viewpoint Manager", checkThree);
checkFour = IsInstalled("ALLUSERSPROFILE", "\\Viewpoint\\Viewpoint Media Player", checkFour);
checkFive = IsInstalled("PROGRAMFILES", "\\Viewpoint\\Common", checkFive);
checkSix = IsInstalled("PROGRAMFILES", "\\Viewpoint\\Viewpoint Experience Technology", checkSix);
checkSeven = IsInstalled("PROGRAMFILES", "\\Viewpoint\\Viewpoint Toolbar V35", checkSeven);
checkEight = IsInstalled("PROGRAMFILES", "\\Viewpoint\\Viewpoint Toolbar", checkEight);
checkNine = IsInstalled("ALLUSERSPROFILE", "\\Viewpoint\\Viewpoint Toolbar", checkNine);
checkTen = IsInstalled("ALLUSERSPROFILE", "\\Viewpoint\\Toolbar Runtime", checkTen);
checkEleven = IsInstalled("CommonProgramFiles", "\\Viewpoint\\Toolbar Runtime", checkEleven);
strcpy(buffer, "");
strcat(buffer, "Viewpoint Media Player?\t");
if (check == 1 || checkFour == 1 || checkFive == 1 || checkSix == 1)
strcat(buffer, "YES");
else
strcat(buffer, "No");
strcat(buffer, "\r\n");
strcat(buffer, "Viewpoint Manager?\t");
if (checkTwo == 1 || checkThree == 1)
strcat(buffer, "YES");
else
strcat(buffer, "No");
strcat(buffer, "\r\n");
strcat(buffer, "Viewpoint Toolbar?\t\t");
if (checkSeven == 1 || checkEight == 1 || checkNine == 1 || checkTen == 1 || checkEleven == 1)
strcat(buffer, "YES");
else
strcat(buffer, "No");
// SetDlgItemText(hDlgWnd, IDC_DLG_TEXT, buffer);
// SetWindowText(hwnd, buffer);
SetDlgItemText(hDlgWnd, IDC_DLG_TEXT, buffer);
// free(buffer);
free(tempBuffer);
free(fullPath);
}
break;I commented out some of those functions trying to figure out the problem. I really have no idea what to do. Some advice would be greatly appreciated. Thank you. ![]()
__________________
The world's first athletic computer geek! The home of PrProgramsStudios How not to post a question: <-- Please don't reply |
|
|
|
|
|
#2 |
|
Expert Programmer
|
Can you step through the code and figure out exactly which line is causing the program to bomb?
__________________
"When in Rome, Do as the Romans Do" "Beauty is in the eye of the BEER holder" "Save your breath your going to need it for your blow up doll later" SearchLores.org |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You cannot free memory which you have not gotten from the heap. Local variables such as tempBuffer are autovariables. These are allocated (in most implementations, on the stack) when the function is entered. They are deallocated when the function returns.
When you use free, you are telling the system to free heap memory located at the pointer that you received when the memory was allocated. Since the auto variable was not allocated from the heap, the heap has no record regarding it, and has little choice but to run off into the weeds and puke on its shoes.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Jan 2007
Location: Cape Town
Posts: 291
Rep Power: 2
![]() |
|
|
|
|
|
|
#5 |
|
Programming Guru
![]() ![]() ![]() |
Very funny.
![]()
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Segmentation Fault | jazz | C | 5 | Aug 21st, 2006 3:16 AM |
| Segmentation Fault | Cipher | C++ | 2 | Feb 21st, 2006 2:10 PM |
| Segmentation Fault!!! | mesagsxbkr | C | 20 | Oct 22nd, 2005 5:04 AM |
| segmentation fault caused by malloc | to66 | C | 7 | Apr 8th, 2005 1:44 PM |
| fprintf segmentation fault | Michael Edgar | C++ | 0 | Mar 21st, 2005 12:21 AM |