davidmoreno / onion

C library to create simple HTTP servers and Web Applications.
http://www.coralbits.com/libonion/
Other
2.01k stars 250 forks source link

Matched the pair of lock and unlock #286

Closed txuna closed 3 years ago

txuna commented 3 years ago

I am a user of onion framework better than anyone else. I decided that matching the lock and unlock pairs is good for users viewing the example/oterm/oterm_handler.c#120

davidmoreno commented 3 years ago

Hi,

I dont quite understand whats the purpose of the commit.

Functionally should do the same. The only difference is one unlock instead of two depending on the if condition.

Can you explain the benefits?

Regards, David.

txuna commented 3 years ago

First, thank you for watching my commit and I not good at english.

Of course, functionally and logically, there are no bugs. However, if the number of locks and unlocks is not match, it can lead to bugs in terms of maintenance. And that code is example code, it can be code that can be referenced by many users(for example, beginner), and it is better to block bugs in advance when users try to extend the code.

For example, when the code expands a lot and someone deletes the unlock part, they think the lock should be deleted as well. If the lock and unlock pairs don't match at this point, they will get a bug. These bugs are difficult to debug.

In conclusion, there are no bugs, but it is important to keep in mind that when the code is expanded, there may be bugs in terms of maintenance. So, I decided that it would be better to match the pair of lock and unlock.

Regards, txuna.