fix stack imbalance pinvoke