commedo's blogger

Thursday, July 15, 2004

[PROGRAMMING TIPS] Using content-type: application/octet-stream HTTP header preventing browser opening a document automatically

Some browsers such as MSIE opening a document automatically without asking to save or open the document. Some people including me it is very annoying. So how to make an application which acts to send a document to a web client such as web browser always download the document rather open it?

There is a simple way to do that by using content-type: application/octet-stream HTTP header instead of using proper MIME-TYPE content-type for a web document to be sent. Most web browsers will downloaded a web document with this content-type including MSIE.

Monday, July 12, 2004

[PROGRAMMING TIPS] Freeing a dynamic allocated variable

You will be mad if you can't locate error in your program especially finally you find out that the cause is only not set your dynamic allocated variable is not set to NULL after freed it, won't you?

There are some tips for freeing a dynamic allocated variable not to cause any trouble in future:
1. Use the same function call to allocate and deallocate a dynamic allocated variable in your whole program.
2. Check if a dynamic allocated variable is NULL or not before freeing it. Please ensure you don't free a dynamic allocated variable values NULL even some function call handle NULL condition.
3. Set a freed dynamic allocated variable to NULL. This will not cause any error if this code is accessed rarely and not repetitively. By experience, this will cause error for repetitive condition.


if (sTemp)
{
free(sTemp);
sTemp = NULL;
}


Reference
Based on my experiences