Sign in to follow this  
Tradone

Can you recognize this segmentation Fault?

Recommended Posts

These are the errors I've received when I used gdb.
(gdb) core-file ShenuUpload.cgi.core
Core was generated by `ShenuUpload.cgi'.
Program terminated with signal 11, Segmentation fault.
#0  0x0808729a in ?? ()
(gdb) bt
#0  0x0808729a in ?? ()
#1  0x00000002 in ?? ()
#2  0x281f8978 in ?? ()
#3  0x080a3e10 in ?? ()
#4  0xbfbfe9b4 in ?? ()
#5  0xbfbfe1e8 in ?? ()
#6  0x00000001 in ?? ()
#7  0xbfbfe9ac in ?? ()
#8  0xbfbfe9b4 in ?? ()
#9  0xbfbfe1c8 in ?? ()
#10 0x08050fb8 in ?? ()
#11 0x00000004 in ?? ()
..
..
..
..
..
#1745 0x00000000 in ?? ()
#1746 0x00000000 in ?? ()
#1747 0x00000000 in ?? ()
#1748 0x00000000 in ?? ()
#1749 0x00000000 in ?? ()
#1750 0x00000000 in ?? ()
#1751 0x00000000 in ?? ()
#1752 0x00000000 in ?? ()
#1753 0x00000000 in ?? ()
#1754 0x00000000 in ?? ()
#1755 0x00000000 in ?? ()
#1756 0x00000000 in ?? ()

#1757 0x00000000 in ?? ()
#1758 0x00000000 in ?? ()
#1759 0x00000000 in ?? ()
#1760 0x00000000 in ?? ()
#1761 0x00000000 in ?? ()
#1762 0x00000000 in ?? ()
#1763 0x00000000 in ?? ()
#1764 0x00000000 in ?? ()
#1765 0x00000000 in ?? ()
#1766 0x00000000 in ?? ()
#1767 0x00000000 in ?? ()
#1768 0x00000000 in ?? ()
#1769 0x00000000 in ?? ()
#1770 0x00000000 in ?? ()

#1771 0x00000000 in ?? ()
#1772 0x00000000 in ?? ()
#1773 0x00000000 in ?? ()
#1774 0x00000000 in ?? ()
#1775 0x00000000 in ?? ()
#1776 0x00000000 in ?? ()
#1777 0x00000000 in ?? ()
#1778 0x00000000 in ?? ()
#1779 0x00000000 in ?? ()
#1780 0x00000000 in ?? ()
#1781 0x00000000 in ?? ()
#1782 0x00000000 in ?? ()
#1783 0x00000000 in ?? ()
#1784 0x00000000 in ?? ()
#1785 0x00000000 in ?? ()
#1786 0x00000000 in ?? ()
#1787 0x00000000 in ?? ()
#1788 0x00000000 in ?? ()
#1789 0x00000000 in ?? ()
#1790 0x00000000 in ?? ()
#1791 0x00000000 in ?? ()
#1792 0x00000000 in ?? ()
#1793 0x00000000 in ?? ()
#1794 0x00000000 in ?? ()
#1795 0x00000000 in ?? ()
#1796 0x00000000 in ?? ()
#1797 0x00000000 in ?? ()
#1798 0x00000000 in ?? ()
#1799 0x00000000 in ?? ()
#1800 0x00000000 in ?? ()
#1801 0x00000000 in ?? ()
#1802 0x00000000 in ?? ()
#1803 0x00000000 in ?? ()
#1804 0x00000000 in ?? ()
#1805 0x00000000 in ?? ()
#1806 0x00000000 in ?? ()
#1807 0x00000000 in ?? ()
#1808 0x00000000 in ?? ()
---Type <return> to continue, or q <return> to quit---
#1809 0x00000000 in ?? ()
#1810 0x00000000 in ?? ()
#1811 0x00000000 in ?? ()
#1812 0x00000000 in ?? ()
#1813 0x00000000 in ?? ()
#1814 0x00000000 in ?? ()
#1815 0x00000000 in ?? ()
#1816 0x00000000 in ?? ()
#1817 0x00000000 in ?? ()
#1818 0x00000000 in ?? ()
#1819 0x00000000 in ?? ()
#1820 0x00000000 in ?? ()
#1821 0x00000000 in ?? ()
#1822 0x00000000 in ?? ()
#1823 0x00000000 in ?? ()
#1824 0x00000000 in ?? ()
#1825 0x00000000 in ?? ()
#1826 0x00000000 in ?? ()
#1827 0x00000000 in ?? ()
#1828 0x00000000 in ?? ()
#1829 0x00000000 in ?? ()
#1830 0x00000000 in ?? ()
#1831 0x00000000 in ?? ()
#1832 0x00000000 in ?? ()
#1833 0x00000000 in ?? ()
#1834 0x00000000 in ?? ()
#1835 0x00000000 in ?? ()
#1836 0x00000000 in ?? ()
#1837 0x00000000 in ?? ()
#1838 0x00000000 in ?? ()
#1839 0x00000000 in ?? ()
#1840 0x00000000 in ?? ()
#1841 0x00000000 in ?? ()
#1842 0x00000000 in ?? ()
#1843 0x00000000 in ?? ()
#1844 0x00000000 in ?? ()
#1845 0x00000000 in ?? ()
#1846 0x00000000 in ?? ()
#1847 0x00000000 in ?? ()
#1848 0x00000000 in ?? ()
#1849 0x00000000 in ?? ()
#1850 0x00000000 in ?? ()
#1851 0x00000000 in ?? ()
#1852 0x00000000 in ?? ()
#1853 0x00000000 in ?? ()
#1854 0x00000000 in ?? ()
#1855 0x00000000 in ?? ()
#1856 0x00000000 in ?? ()
#1857 0x00000000 in ?? ()
#1858 0x00000000 in ?? ()
#1859 0x00000000 in ?? ()
#1860 0x00000000 in ?? ()
#1861 0x00000000 in ?? ()
#1862 0x00000000 in ?? ()
#1863 0x00000000 in ?? ()
#1864 0x00000000 in ?? ()
#1865 0x00000000 in ?? ()
#1866 0x00000000 in ?? ()
#1867 0x00000000 in ?? ()
#1868 0x00000000 in ?? ()
#1869 0x00000000 in ?? ()
#1870 0x00000000 in ?? ()
#1871 0x00000000 in ?? ()
#1872 0x00000000 in ?? ()
#1873 0x00000000 in ?? ()
#1874 0x00000000 in ?? ()
#1875 0x00000000 in ?? ()
---Type <return> to continue, or q <return> to quit---
#1876 0x00000000 in ?? ()
#1877 0x00000000 in ?? ()
#1878 0x00000000 in ?? ()
#1879 0x00000000 in ?? ()
#1880 0x00000000 in ?? ()
#1881 0x00000000 in ?? ()
#1882 0x00000000 in ?? ()
#1883 0x00000000 in ?? ()
#1884 0x00000000 in ?? ()
#1885 0x00000000 in ?? ()
#1886 0x00000000 in ?? ()
#1887 0x00000000 in ?? ()
#1888 0x00000000 in ?? ()
#1889 0x00000000 in ?? ()
#1890 0x00000000 in ?? ()
#1891 0x00000000 in ?? ()
#1892 0x00000000 in ?? ()
#1893 0x00000000 in ?? ()
#1894 0x00000000 in ?? ()
#1895 0x00000000 in ?? ()
#1896 0x00000000 in ?? ()
#1897 0x00000000 in ?? ()
#1898 0x00000000 in ?? ()
#1899 0x00000000 in ?? ()
#1900 0x00000000 in ?? ()
#1901 0x00000000 in ?? ()
#1902 0x00000000 in ?? ()
#1903 0x00000000 in ?? ()
#1904 0x00000000 in ?? ()
#1905 0x00000000 in ?? ()
#1906 0x00000000 in ?? ()
#1907 0x00000000 in ?? ()
#1908 0x00000000 in ?? ()
#1909 0x00000000 in ?? ()
#1910 0x00000000 in ?? ()
#1911 0x00000000 in ?? ()
#1912 0x00000000 in ?? ()
#1913 0x00000000 in ?? ()
#1914 0x00000000 in ?? ()
#1915 0x00000000 in ?? ()
#1916 0x00000000 in ?? ()
#1917 0x00000000 in ?? ()
#1918 0x00000000 in ?? ()
#1919 0x00000000 in ?? ()
#1920 0x00000000 in ?? ()
#1921 0x00000000 in ?? ()
#1922 0x00000000 in ?? ()
#1923 0x102454ff in ?? ()
#1924 0x2024448d in ?? ()
#1925 0x5440f750 in ?? ()
#1926 0x00020000 in ?? ()
#1927 0x688e0375 in ?? ()
#1928 0x01a1b814 in ?? ()
#1929 0xcd500000 in ?? ()
#1930 0x90feeb80 in ?? ()
#1931 0x102454ff in ?? ()
#1932 0x1424448d in ?? ()
#1933 0x5440f750 in ?? ()
#1934 0x00020000 in ?? ()
#1935 0x688e0375 in ?? ()
#1936 0x0158b814 in ?? ()
#1937 0xcd500000 in ?? ()
#1938 0x90feeb80 in ?? ()
#1939 0x102454ff in ?? ()
#1940 0x1424448d in ?? ()
#1941 0x1840f750 in ?? ()
#1942 0x00020000 in ?? ()
---Type <return> to continue, or q <return> to quit---
#1943 0x688e0375 in ?? ()
#1944 0x0067b844 in ?? ()
#1945 0xcd500000 in ?? ()
#1946 0x90feeb80 in ?? ()
#1947 0xbfbfe9ac in ?? ()
#1948 0x00000001 in ?? ()
#1949 0xbfbfe9b4 in ?? ()
#1950 0x0000001b in ?? ()
Cannot access memory at address 0xbfc00000




Thanks, and I am getting this problem with this source code:
//DirectoryInformation.h
class DirectoryInformation{
	public:
		DirectoryInformation( std::string para_directoryPath, std::string para_sortingAgent );
		void Set();
		bool FolderExist( std::string para_checkFolder);
		bool FileExist( std::string para_checkFile );
		void Print();
	//end public:

	private:
		std::string directoryPath;
		std::string sortingAgent;

		std::vector<std::string> files;
		std::vector<std::string> directories;

		std::map<std::string, std::string> innerMap;
		std::map<std::string, std::map<std::string, std::string> > directoriesMap;
		std::map<std::string, std::map<std::string, std::string> > filesMap;
	//end private:
};


//DirectoryInformation.cpp
DirectoryInformation::DirectoryInformation(std::string para_directoryPath, std::string para_sortingAgent):directoryPath(para_directoryPath), sortingAgent(para_sortingAgent){

	DIR *pdir;
	struct dirent *pent;

	pdir=opendir( directoryPath.c_str() ); //"." refers to the current dir
	if (!pdir){
		std::cout << "opendir() failure; terminating";
		exit(1);
	}
	errno=0; 
	while ( (pent=readdir(pdir)) ){

		int i, type;
		struct stat statinfo;
		std::string tempString=directoryPath;
		tempString+=pent->d_name;
		if ( tempString != directoryPath+"." && tempString != directoryPath+".." ){
			if(lstat( tempString.c_str() ,&statinfo) == -1){
				std::cout << strerror(errno) << std::endl;
				perror("lstat");
				exit(1);
			}
			tempString=pent->d_name;

			type = statinfo.st_mode & S_IFMT;
			switch(type){
				case S_IFDIR : 
					directories.push_back( tempString );
					directories.size();
					break;

				case S_IFREG :
					files.push_back( tempString );
					files.size();
					break;

			}
		}

	}
	if (errno){
		std::cout << "readdir() failture; terminating";
		exit(1);
	}
	closedir(pdir);
}

//main.cpp
			DirectoryInformation* fileDirectory = NULL;
			std::string randomString;

			if ( **tempDirectory == "" ){
				while( 1 ){
					randomString=algorithms::Instance().GetRandomString();
					fileDirectory = new DirectoryInformation( "./temp/", "date" );
					if ( !fileDirectory->FolderExist(randomString) )
						break;
				}
			}
			else{
				randomString=**tempDirectory;
			}



Share this post


Link to post
Share on other sites
First, I'd like to say thank you for the quick reply.

Quote:
Original post by swiftcoder
That is a pretty useless debugger dump [smile]

Sorry, I don't know much about what is considered important information. I thought it just might help.

Quote:
Original post by swiftcoder
I would say it is a invalid pointer causing that, why don't you check if you are accessing any un-initiallized pointer variables.

Thanks, I'll look into that.

Share this post


Link to post
Share on other sites
It doesn't look like you have any debug symbols either for gdb... make sure you're compiling the program (assuming gcc) with the -g flag so you can get function/variable names.

Also, do you know why you have nearly 2000 frames that claim to be functions at address 0x0?

Share this post


Link to post
Share on other sites
another question,

is it safe to do this?

std::string* hello=NULL;
hello = new std::string("123");
hello = new std::string("444");

???
is this safe?
or is it just memory leakage?

Share this post


Link to post
Share on other sites
Quote:
Original post by elijah_taylor
Also, do you know why you have nearly 2000 frames that claim to be functions at address 0x0?


I have no idea.
But, lemme think... some kind of infinite loop?
Idk, I only have 1 while loop, and i think it's fine.

Share this post


Link to post
Share on other sites

if ( **tempDirectory == "" ){
while( 1 ){
randomString=algorithms::Instance().GetRandomString();
fileDirectory = new DirectoryInformation( "./temp/", "date" );
if ( !fileDirectory->FolderExist(randomString) ){
break;
}
delete fileDirectory;
}
}
else{
fileDirectory = new DirectoryInformation( "./temp/", "date" );
randomString=**tempDirectory;
}


it was rather a dumb mistake.

fileDirectory = new DirectoryInformation( "./temp/", "date" );
after the else{} was the problem,
so I kept trying to access data from a NULL pointer as swiftcoder suggested

oh and I added a delte fileDirectory to prevent memory leakage

Share this post


Link to post
Share on other sites
Quote:
Original post by Tradone
another question,

is it safe to do this?

std::string* hello=NULL;
hello = new std::string("123");
hello = new std::string("444");

???
is this safe?
or is it just memory leakage?


It would cause a memory leak. You should delete hello before assigning it a new value.

Share this post


Link to post
Share on other sites
Quote:
Original post by Roboguy
It would cause a memory leak. You should delete hello before assigning it a new value.


Thanks, just double checking.

Share this post


Link to post
Share on other sites
Quote:
Original post by elijah_taylor
It doesn't look like you have any debug symbols either for gdb... make sure you're compiling the program (assuming gcc) with the -g flag so you can get function/variable names.

Also, do you know why you have nearly 2000 frames that claim to be functions at address 0x0?


I just encountered a runtime, and it's giving me the same results.
please help as to why I have nearly 2000 frames that claim to be functions at address 0x0? awk

Share this post


Link to post
Share on other sites
Without knowing more about your program (what libraries you're linking in, what the general structure of everything is, etc) it's hard to say what's causing the strange stack. It maybe is some library calls whose addresses are misunderstood by gdb so it defaults to 0x0. The point is that it really can't be functions at 0x0, because dereferencing a NULL function pointer would have segfaulted much earlier in the program.

It could be something as simple as some sort of memory corruption where you're accidentally writing over part of the stack (for instance, where the frame pointer to the previous frame is stored) somewhere in your program, which would probably munge the whole thing up. That'd be a particularly difficult bug to find... if that's the case, look especially for buffer overflows and out of bounds array access.

As I stated before, compiling for gdb (-g for gcc) will give you much better debug info, it should at least tell you functions for each of the stack frames (I believe it will display what library/address for linked in functions from compiled libraries), so it's really essential if you're using gdb with any seriousness.

In addition to the strange address (0x0), I'm stunned by the shear number of frames on the stack... if it's some corruption that may explain it, but otherwise, if you actually have 2000 some-odd functions in there, I'd be worried about overflowing your stack. Check your compiler and see what stack size you're allocating; that may afterall be part of the problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this