I'm a Masters student in computer science. My current advisor is completely un-professional. He doesn't only write bad letters of recommendations for his students in order to keep them working for him, he even wrote bad letters of recommendations for students who did not ask him for these letters. I think this is egregious. I don't really know why. It might be psychiatric issues. Now, he is the only one in my school doing research. I don't know how to deal with it. Any suggestions would be really appreciated.
Run away! The most important thing to success in your graduate education is your desire to succeed and your advisors desire for you to succeed. I've had friends and family with advisors who were immoral or emotionally unstable, and they are much happier now that they switched institutions/advisers or left the field entirely.
I think the answer largely depends on your particular circumstances. You mention bad recommendation letters. Okay, this is awful, but apart from this issue it seems you don't have any other complaints. Thus your course of actions depends on whether (1) you need recommendation letters while you are doing your masters and (2) these letters have to be from your supervisor.
If changing your supervisor and/or school is not an option, think about these questions. In a sense, your original question begs the trivial answer: if your supervisor writes bad and unwanted letters, you have to get these letters elsewhere and somewhat quietly.