not_unlocked_mutex.cocci 1.5 KB

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