[MDEV-26557] Improper locking bugs due to the unreleased locks before program eixt Created: 2021-09-07  Updated: 2021-09-07

Status: Open
Project: MariaDB Server
Component/s: None
Affects Version/s: 10.6.4
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Ryan Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Environment:

All



 Description   

Hi developers, in the below codes, the lock LOCK_thread_count could be not released before program's exit exit(1);. I think it is better to write pthread_mutex_unlock(&LOCK_thread_count); * before the *exit(1); for better resource management and code symmetry. Thanks!

https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/storage/maria/unittest/ma_pagecache_single.c#L815-L823



 Comments   
Comment by Ryan [ 2021-09-07 ]

Similarly, the lock counter_mutex could be not released before the program's exit exit(1); in the function safe_exit.

https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/client/mysqlimport.c#L564-L584

Comment by Ryan [ 2021-09-07 ]

The lock LOCK_thread_count is not released correctly before the program's exit exit(1); (Line 460).

https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/storage/maria/unittest/ma_pagecache_consist.c#L434-L460

Comment by Ryan [ 2021-09-07 ]

The lock LOCK_thread_count is not released correctly before the program's exit exit(1);

https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/tests/thread_test.c#L218-L229

Comment by Ryan [ 2021-09-07 ]

Here are many similar cases:

https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/storage/maria/unittest/ma_pagecache_rwconsist.c#L297-L314
https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/storage/maria/unittest/ma_pagecache_rwconsist2.c#L293-L320
https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/storage/maria/unittest/ma_test_loghandler_multithread-t.c#L383-L395
https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/mysys/thr_mutex.c#L238-L265
https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/mysys/thr_mutex.c#L290-L306
https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/mysys/thr_mutex.c#L409-L430
https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/mysys/thr_mutex.c#L461-L491
https://github.com/MariaDB/server/blob/57f14eab20ae2733eb341f3d293515a10a40bc48/mysys/thr_mutex.c#L493-L517

Comment by Ryan [ 2021-09-07 ]

They are small, harmless errors since the program exits, and all of the program resources will be cleaned up by some common OS. However, other OS systems (e.g., embedded systems) do not automatically free some resources at the exit. It is a good manner for resource management. Adding the unlock statement adds symmetry, so the code looks better.

Generated at Thu Feb 08 09:46:13 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.