![]() |
Seg Fault Mem Leak
Alright, this function is in a thread which is reading lines from a file which will never be longer than 16 chars. inside the while(1) loop, if I comment out everything except an output of ptrr and the fgets, there is no seg fault. Also, I can comment out the push_backs and I still get the seg fault. Can someone please help me figure this one out?
Code:
void * read_file(void*){ |
Re: Seg Fault Mem Leak
(1) Please use code blocks.
(2) The problem may not be in the code you've posted. Create a testbed that calls this from a simple main() function and make sure that reproduces the problem. If it does then post the new code here WITH CODE BLOCKS and we can have a look. Out of interest, does the maximum line length of 16 characters include room for end of line and terminating NULL? So if you have the string "Hello\n" for example, that's actually 7 characters, and if you mean the "Hello" part is limited to 16 characters then you need larger arrays than just [16]. |
Re: Seg Fault Mem Leak
Sorry about that.
Code:
void * read_file(void*){ |
Re: Seg Fault Mem Leak
Quote:
|
Re: Seg Fault Mem Leak
Alright I did everything from point 2 you mentioned. Same result. The segfault happens after about 20 seconds of reading the file. Yes, 16 is plenty as the actual line is 14 chars.
|
Re: Seg Fault Mem Leak
The memory leak could be the cause; you new[] three character arrays but you don't delete[] them. This isn't Java and you don't get a free garbage collector. I'm not sure why you want to use new/delete here anyway;
Code:
char ptrr[16]; |
Re: Seg Fault Mem Leak
Alright, I have played with more options and now have this. It is still giving a seg fault
Code:
void * read_file(void*){ |
Re: Seg Fault Mem Leak
Code:
char ptrr[256] ; |
Re: Seg Fault Mem Leak
I tried changing the line to
Code:
char index[256] ; |
Re: Seg Fault Mem Leak
Whoops, sorry, turns out it's me not paying attention. So index and value don't need initialising at all, since they take on values returned by strtok. This also explains why you leak 512 bytes each time the function is called, which could be why you get a segfault.
|
| All times are GMT +5.5. The time now is 08:03. |