0

Since I'm close, I will not be posting any of my code up front. I'm at a point where everything checks except these two

:( Requesting cat.jpg returns 200, image/jpeg, and correct image

:( Requesting two files in a row (cat.html then cat.jpg) succeeds

Both coming up with

\ expected an exit code of 0, not standard error of "======= Backtrace: ...

I've read that this means there is a segment fault and indeed there is, but I'm having trouble knowing where.

I am using fgetc to get int c from file and stop the loop using EOF. I've read there are problems with that involving the beginning of images, others are saying it works fine.

In the loop I check if I have expended my buffer and if so realloc buffer based on the length times two.

I am fine with posting my code if needed for clarification but would rather do so as needed.

I have done my best to ensure that I do not deallocate memory that would still be used (copying buffer to content). I do deallocate buffer after I use memcpy to move the data from buffer to content.

Here are the CS50 Check Results: https://sandbox.cs50.net/checks/516bbb50cb274eef9fd9c0aee587e957

1

You need to "know where" before you can make progress. How about sending a smaller file hello.html? favicon.ico? through server under valgrind and see what it reports. This command line valgrind -v --leak-check=full --show-leak-kinds=all --track-origins=yes gives a lot of feedback. Else, gdb is your best bet. I know it would be tedious one char at a time. You can use something like 512 c to stop at a breakpoint after 512 iters.

| improve this answer | |
  • It breaks when it gets to free content, outside of my load function and inside the transfer function. – Bob R. Sep 20 '16 at 0:20
  • At the end I have my locals as buffer = 0x607340 "\377\330\377", <incomplete sequence \340> c = 217 i = 26860 which appears to be correct. buffer will be placed into content (memcpy) – Bob R. Sep 20 '16 at 0:38
  • >*** Error in /home/ubuntu/workspace/pset6/server': free(): invalid next >size (normal): 0x0000000000607550 *** >Program received signal SIGABRT, Aborted. >0x00007ffff7745c37 - address of content` Valgrind gives me Invalid write of size 1 - 0 bytes after block size of 512 alloc'd - line 634 which is char* buffer = malloc(BYTES); Getting some other feedback from my parse method as well about invalid read size when I use strtok to set the value of method, requestTarget, and httpVersion which were not there before. I copied your command from our chat and have been using it a lot. – Bob R. Sep 20 '16 at 0:46
  • When I run valgrind with those arguments on favicon.ico I do have invalid read and writes in my parse method (using strtok and strcpy) to check each segment. I wouldn't think that the parse method would have anything to do with this as the image loads fine and so do the pages. Even when a page is called a subsequent call for the favicon.ico file is captured correctly. My variables are initialized at the beginning of each call and every malloc (and friends) has a free where appropriate. I have tried troubleshooting by using free(buffer) and commenting it out just in case. – Bob R. Sep 20 '16 at 1:43
  • I'm utterly lost in this, I have valgrind errors going back to parse, and after working on this same piece for a few days trying to correct what I've already written, I feel that the best option at this point is just to re-write both my parse and load methods using valgrind as I go to cut down on the number of errors. I know my indexes and lookup functions are correct, but I need to take a break from this. I appreciate the help and I'll be using the valgrind command you posted, it has been helpful. – Bob R. Sep 20 '16 at 4:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .