not_unlocked_mutex.cocci 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. virtual context
  17. virtual org
  18. virtual patch
  19. virtual report
  20. @initialize:python depends on report || org@
  21. msg="The mutex \"%s\" is not unlocked when leaving \"%s\""
  22. from re import sub
  23. orgmsg = sub(r'(%[a-z])', r'=\1=', msg)
  24. @r@
  25. expression E;
  26. identifier func;
  27. position p;
  28. @@
  29. func(...)
  30. {
  31. <...
  32. _STARPU_PTHREAD_MUTEX_LOCK(E);
  33. <... when != _STARPU_PTHREAD_MUTEX_UNLOCK(E)
  34. if (...)
  35. {
  36. ... when != _STARPU_PTHREAD_MUTEX_UNLOCK(E)
  37. return@p ...;
  38. }
  39. ...>
  40. _STARPU_PTHREAD_MUTEX_UNLOCK(E);
  41. ...>
  42. }
  43. @depends on r && context@
  44. position r.p;
  45. @@
  46. * return@p ...;
  47. @script:python depends on r && org@
  48. ps << r.p;
  49. f << r.func;
  50. E << r.E;
  51. @@
  52. for p in ps:
  53. coccilib.org.print_todo(p, orgmsg % (E, f))
  54. @depends on r && patch@
  55. expression r.E;
  56. position r.p;
  57. @@
  58. + _STARPU_PTHREAD_MUTEX_UNLOCK(E);
  59. return@p ...;
  60. @script:python depends on r && report@
  61. ps << r.p;
  62. f << r.func;
  63. E << r.E;
  64. @@
  65. for p in ps:
  66. coccilib.org.print_todo(p, msg % (E, f))