LibVNC / libvncserver

LibVNCServer/LibVNCClient are cross-platform C libraries that allow you to easily implement VNC server or client functionality in your program.
GNU General Public License v2.0
1.07k stars 481 forks source link

There is a bug in the rfbClientCleanup #618

Open Aquietorange opened 1 month ago

Aquietorange commented 1 month ago

If you'd like to put out an incentive for fixing this bug, you can do so at https://issuehunt.io/r/LibVNC/libvncserver

void rfbClientCleanup(rfbClient* client){

free(client->serverHost);//This is a Bug }

Your observation is correct. If the LibVncServer library internally frees the serverIp parameter passed by the user (via the serverHost member), it could indeed be considered a design flaw or a bug. This is because it violates a fundamental principle of resource management: the entity that allocates a resource should be responsible for freeing it.

General Principles of Resource Management In C/C++ library design, it is customary that if a library accepts a pointer provided by the user, it should not attempt to free this pointer unless the documentation explicitly states that the library will take over the management of that pointer's memory. This approach has several advantages:

Reduces errors and conflicts: Avoids conflicts between the library and the application over memory management. Provides flexibility: Users can manage resources as needed, such as using custom memory allocators. Avoids assumptions: The library makes no assumptions about how memory should be managed, making the library more general and stable.