All normal exit paths from your system routine are required to call the IDL_KW_FREE macro prior to returning. This macro must be called exactly once for every call to IDL_KWProcessByOffset().
You must therefore structure your code so that IDL_KW_FREE executes before any return statement. Many functions to not use an explicit return statement, relying on the implicit return that occurs when execution comes to the end of the function. In such a case, IDL_KW_FREE must be the last statement in the function.