diff mbox

[2/2] libselinux, libsemanage: swig: use SWIG_fail when an error occurs

Message ID 20161114215712.18962-2-nicolas.iooss@m4x.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nicolas Iooss Nov. 14, 2016, 9:57 p.m. UTC
Using SWIG_fail in the Python SWIG wrappers makes the wrapping function
destroy/free the memory which could have been dynamically allocated
before calling the wrapped function. This thus prevents possible memory
leaks in the wrappers of set*con(), set*con_raw(), security_compute_*(),
etc.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 libselinux/src/exception.sh  | 2 +-
 libsemanage/src/exception.sh | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Stephen Smalley Nov. 15, 2016, 4:14 p.m. UTC | #1
On 11/14/2016 04:57 PM, Nicolas Iooss wrote:
> Using SWIG_fail in the Python SWIG wrappers makes the wrapping function
> destroy/free the memory which could have been dynamically allocated
> before calling the wrapped function. This thus prevents possible memory
> leaks in the wrappers of set*con(), set*con_raw(), security_compute_*(),
> etc.
> 
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>

Thanks, applied both patches.

> ---
>  libselinux/src/exception.sh  | 2 +-
>  libsemanage/src/exception.sh | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/libselinux/src/exception.sh b/libselinux/src/exception.sh
> index a3ff83235ced..d6c8c71713ad 100755
> --- a/libselinux/src/exception.sh
> +++ b/libselinux/src/exception.sh
> @@ -8,7 +8,7 @@ echo "
>    \$action 
>    if (result < 0) {
>       PyErr_SetFromErrno(PyExc_OSError);
> -     return NULL;
> +     SWIG_fail;
>    }
>  }
>  "
> diff --git a/libsemanage/src/exception.sh b/libsemanage/src/exception.sh
> index a4095f4f8ba6..97bc2ae879f2 100644
> --- a/libsemanage/src/exception.sh
> +++ b/libsemanage/src/exception.sh
> @@ -4,7 +4,7 @@ echo "
>    \$action
>    if (result < 0) {
>       PyErr_SetFromErrno(PyExc_OSError);
> -     return NULL;
> +     SWIG_fail;
>    }
>  }
>  "
>
diff mbox

Patch

diff --git a/libselinux/src/exception.sh b/libselinux/src/exception.sh
index a3ff83235ced..d6c8c71713ad 100755
--- a/libselinux/src/exception.sh
+++ b/libselinux/src/exception.sh
@@ -8,7 +8,7 @@  echo "
   \$action 
   if (result < 0) {
      PyErr_SetFromErrno(PyExc_OSError);
-     return NULL;
+     SWIG_fail;
   }
 }
 "
diff --git a/libsemanage/src/exception.sh b/libsemanage/src/exception.sh
index a4095f4f8ba6..97bc2ae879f2 100644
--- a/libsemanage/src/exception.sh
+++ b/libsemanage/src/exception.sh
@@ -4,7 +4,7 @@  echo "
   \$action
   if (result < 0) {
      PyErr_SetFromErrno(PyExc_OSError);
-     return NULL;
+     SWIG_fail;
   }
 }
 "