diff options
Diffstat (limited to 'lib/crypto/c_src/check_erlang.cocci')
-rw-r--r-- | lib/crypto/c_src/check_erlang.cocci | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/lib/crypto/c_src/check_erlang.cocci b/lib/crypto/c_src/check_erlang.cocci index bdb99d5bb0..eba0e3935c 100644 --- a/lib/crypto/c_src/check_erlang.cocci +++ b/lib/crypto/c_src/check_erlang.cocci @@ -39,7 +39,8 @@ position p; goto L; ... when strict, forall - enif_release_resource(CTX) + if (CTX) + enif_release_resource(CTX); // After calling enif_alloc_binary(), you must either release it with @@ -93,7 +94,7 @@ position pa, pm, pr; // enif_has_pending_exception returns true if exception pending @erlang_check_void@ -identifier FUNCVOID =~ "^(enif_free|enif_mutex_destroy|enif_mutex_lock|enif_mutex_unlock|enif_release_binary|enif_release_resource|enif_rwlock_destroy|enif_rwlock_rlock|enif_rwlock_runlock|enif_rwlock_rwlock|enif_rwlock_rwunlock|enif_system_info)$"; +identifier FUNCVOID =~ "^(enif_free|enif_mutex_destroy|enif_mutex_lock|enif_mutex_unlock|enif_release_binary|enif_rwlock_destroy|enif_rwlock_rlock|enif_rwlock_runlock|enif_rwlock_rwlock|enif_rwlock_rwunlock|enif_system_info)$"; position p; @@ @@ -133,6 +134,22 @@ position p; ) +@erlang_check_null_free@ +expression X; +identifier FUNCFREE =~ "^(enif_release_resource)$"; +position p; +@@ + + if ( +( + X +| + X != NULL +) + ) + FUNCFREE(X)@p; + + @erlang_check_new@ expression RET; identifier FUNCNEW =~ "^(enif_make_atom|enif_make_badarg|enif_make_binary|enif_make_int|enif_make_list|enif_make_list_from_array|enif_make_resource|enif_make_tuple|enif_raise_exception|enif_schedule_nif|enif_thread_self)$"; @@ -149,7 +166,7 @@ position p; // Flag any calls that aren't part of the above pattern. @enif_alloc_not_free@ -identifier FUNCVOID =~ "^(enif_free|enif_mutex_destroy|enif_mutex_lock|enif_mutex_unlock|enif_release_binary|enif_release_resource|enif_rwlock_destroy|enif_rwlock_rlock|enif_rwlock_runlock|enif_rwlock_rwlock|enif_rwlock_rwunlock|enif_system_info)$"; +identifier FUNCVOID =~ "^(enif_free|enif_mutex_destroy|enif_mutex_lock|enif_mutex_unlock|enif_release_binary|enif_rwlock_destroy|enif_rwlock_rlock|enif_rwlock_runlock|enif_rwlock_rwlock|enif_rwlock_rwunlock|enif_system_info)$"; position pvoid != {erlang_check_void.p,enif_alloc_binary.pr}; identifier FUNCNULL =~ "^(enif_alloc|enif_alloc_resource|enif_dlopen|enif_dlsym|enif_make_new_binary|enif_mutex_create|enif_open_resource_type|enif_realloc|enif_rwlock_create)$"; @@ -161,6 +178,9 @@ position pnot != {erlang_check_not.p,enif_alloc_binary.pa}; identifier FUNCNEW =~ "^(enif_make_atom|enif_make_badarg|enif_make_binary|enif_make_int|enif_make_list|enif_make_list_from_array|enif_make_resource|enif_make_tuple|enif_raise_exception|enif_schedule_nif|enif_thread_self)$"; position pnew != {erlang_check_new.p,enif_alloc_binary.pm}; +identifier FUNCFREE =~ "^(enif_release_resource)$"; +position pfree != {enif_alloc_resource.p,erlang_check_null_free.p}; + @@ ( @@ -171,4 +191,6 @@ position pnew != {erlang_check_new.p,enif_alloc_binary.pm}; * FUNCNOT(...)@pnot | * FUNCNEW(...)@pnew +| +* FUNCFREE(...)@pfree ) |