diff mbox series

[userspace,2/4] libsepol: remove unused cil_mem_error_handler

Message ID 20200122154655.257233-3-omosnace@redhat.com (mailing list archive)
State Superseded
Headers show
Series Fix build with -fno-common | expand

Commit Message

Ondrej Mosnacek Jan. 22, 2020, 3:46 p.m. UTC
It is declared in an internal header but never defined. Remove it.

Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
---
 libsepol/cil/src/cil_mem.h     | 1 -
 libsepol/cil/src/cil_strpool.c | 2 --
 2 files changed, 3 deletions(-)

Comments

James Carter Jan. 22, 2020, 6:54 p.m. UTC | #1
On 1/22/20 10:46 AM, Ondrej Mosnacek wrote:
> It is declared in an internal header but never defined. Remove it.
> 
> Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> ---
>   libsepol/cil/src/cil_mem.h     | 1 -
>   libsepol/cil/src/cil_strpool.c | 2 --
>   2 files changed, 3 deletions(-)
> 
> diff --git a/libsepol/cil/src/cil_mem.h b/libsepol/cil/src/cil_mem.h
> index 902ce131..794f02a3 100644
> --- a/libsepol/cil/src/cil_mem.h
> +++ b/libsepol/cil/src/cil_mem.h
> @@ -36,7 +36,6 @@ void *cil_calloc(size_t num_elements, size_t element_size);
>   void *cil_realloc(void *ptr, size_t size);
>   char *cil_strdup(const char *str);
>   int cil_asprintf(char **strp, const char *fmt, ...);
> -void (*cil_mem_error_handler)(void);
>   
>   #endif /* CIL_MEM_H_ */
>   
> diff --git a/libsepol/cil/src/cil_strpool.c b/libsepol/cil/src/cil_strpool.c
> index 97d4c4b9..508541d6 100644
> --- a/libsepol/cil/src/cil_strpool.c
> +++ b/libsepol/cil/src/cil_strpool.c
> @@ -80,7 +80,6 @@ char *cil_strpool_add(const char *str)
>   		int rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
>   		if (rc != SEPOL_OK) {
>   			pthread_mutex_unlock(&cil_strpool_mutex);
> -			(*cil_mem_error_handler)();
>   			pthread_mutex_lock(&cil_strpool_mutex);
>   		}
>   	}

I removed the cil_mem_error_handler stuff last Fall (see commit 4459d635). I 
guess that I must have missed these somehow.

In the other places where I removed it, I replaced it with the inlined default 
hanlder which consisted of the following:

   cil_log(CIL_ERR, "Failed to allocate memory\n");
   exit(1);

Since we are existing, the pthread_mutex_lock() call can be removed.

> @@ -104,7 +103,6 @@ void cil_strpool_init(void)
>   		cil_strpool_tab = hashtab_create(cil_strpool_hash, cil_strpool_compare, CIL_STRPOOL_TABLE_SIZE);
>   		if (cil_strpool_tab == NULL) {
>   			pthread_mutex_unlock(&cil_strpool_mutex);
> -			(*cil_mem_error_handler)();
>   			return;
>   		}
>   	}
> 

Same thing here, but now the return won't be needed.

Thanks,
Jim
Ondrej Mosnacek Jan. 23, 2020, 11:59 a.m. UTC | #2
On Wed, Jan 22, 2020 at 7:54 PM jwcart2 <jwcart2@tycho.nsa.gov> wrote:
> On 1/22/20 10:46 AM, Ondrej Mosnacek wrote:
> > It is declared in an internal header but never defined. Remove it.
> >
> > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
> > ---
> >   libsepol/cil/src/cil_mem.h     | 1 -
> >   libsepol/cil/src/cil_strpool.c | 2 --
> >   2 files changed, 3 deletions(-)
> >
> > diff --git a/libsepol/cil/src/cil_mem.h b/libsepol/cil/src/cil_mem.h
> > index 902ce131..794f02a3 100644
> > --- a/libsepol/cil/src/cil_mem.h
> > +++ b/libsepol/cil/src/cil_mem.h
> > @@ -36,7 +36,6 @@ void *cil_calloc(size_t num_elements, size_t element_size);
> >   void *cil_realloc(void *ptr, size_t size);
> >   char *cil_strdup(const char *str);
> >   int cil_asprintf(char **strp, const char *fmt, ...);
> > -void (*cil_mem_error_handler)(void);
> >
> >   #endif /* CIL_MEM_H_ */
> >
> > diff --git a/libsepol/cil/src/cil_strpool.c b/libsepol/cil/src/cil_strpool.c
> > index 97d4c4b9..508541d6 100644
> > --- a/libsepol/cil/src/cil_strpool.c
> > +++ b/libsepol/cil/src/cil_strpool.c
> > @@ -80,7 +80,6 @@ char *cil_strpool_add(const char *str)
> >               int rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
> >               if (rc != SEPOL_OK) {
> >                       pthread_mutex_unlock(&cil_strpool_mutex);
> > -                     (*cil_mem_error_handler)();
> >                       pthread_mutex_lock(&cil_strpool_mutex);
> >               }
> >       }
>
> I removed the cil_mem_error_handler stuff last Fall (see commit 4459d635). I
> guess that I must have missed these somehow.
>
> In the other places where I removed it, I replaced it with the inlined default
> hanlder which consisted of the following:
>
>    cil_log(CIL_ERR, "Failed to allocate memory\n");
>    exit(1);
>
> Since we are existing, the pthread_mutex_lock() call can be removed.

I see, thanks for pointing it out! I'm now quite embarrassed for not
noticing the needless lock-unlock sequence I left behind in this patch
:)

I will rework this patch to match commit 4459d635 in v2.

>
> > @@ -104,7 +103,6 @@ void cil_strpool_init(void)
> >               cil_strpool_tab = hashtab_create(cil_strpool_hash, cil_strpool_compare, CIL_STRPOOL_TABLE_SIZE);
> >               if (cil_strpool_tab == NULL) {
> >                       pthread_mutex_unlock(&cil_strpool_mutex);
> > -                     (*cil_mem_error_handler)();
> >                       return;
> >               }
> >       }
> >
>
> Same thing here, but now the return won't be needed.
>
> Thanks,
> Jim
>
>
> --
> James Carter <jwcart2@tycho.nsa.gov>
> National Security Agency
>

--
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.
diff mbox series

Patch

diff --git a/libsepol/cil/src/cil_mem.h b/libsepol/cil/src/cil_mem.h
index 902ce131..794f02a3 100644
--- a/libsepol/cil/src/cil_mem.h
+++ b/libsepol/cil/src/cil_mem.h
@@ -36,7 +36,6 @@  void *cil_calloc(size_t num_elements, size_t element_size);
 void *cil_realloc(void *ptr, size_t size);
 char *cil_strdup(const char *str);
 int cil_asprintf(char **strp, const char *fmt, ...);
-void (*cil_mem_error_handler)(void);
 
 #endif /* CIL_MEM_H_ */
 
diff --git a/libsepol/cil/src/cil_strpool.c b/libsepol/cil/src/cil_strpool.c
index 97d4c4b9..508541d6 100644
--- a/libsepol/cil/src/cil_strpool.c
+++ b/libsepol/cil/src/cil_strpool.c
@@ -80,7 +80,6 @@  char *cil_strpool_add(const char *str)
 		int rc = hashtab_insert(cil_strpool_tab, (hashtab_key_t)strpool_ref->str, strpool_ref);
 		if (rc != SEPOL_OK) {
 			pthread_mutex_unlock(&cil_strpool_mutex);
-			(*cil_mem_error_handler)();
 			pthread_mutex_lock(&cil_strpool_mutex);
 		}
 	}
@@ -104,7 +103,6 @@  void cil_strpool_init(void)
 		cil_strpool_tab = hashtab_create(cil_strpool_hash, cil_strpool_compare, CIL_STRPOOL_TABLE_SIZE);
 		if (cil_strpool_tab == NULL) {
 			pthread_mutex_unlock(&cil_strpool_mutex);
-			(*cil_mem_error_handler)();
 			return;
 		}
 	}