mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fix undefined behavior in free
@ 2017-06-27 17:58 Alexander Monakov
  2017-07-04 21:11 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Monakov @ 2017-06-27 17:58 UTC (permalink / raw)
  To: musl

---
 src/malloc/malloc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c
index 720fa696..ef4c7368 100644
--- a/src/malloc/malloc.c
+++ b/src/malloc/malloc.c
@@ -463,14 +463,15 @@ copy_realloc:
 
 void free(void *p)
 {
-	struct chunk *self = MEM_TO_CHUNK(p);
-	struct chunk *next;
+	struct chunk *self, *next;
 	size_t final_size, new_size, size;
 	int reclaim=0;
 	int i;
 
 	if (!p) return;
 
+	self = MEM_TO_CHUNK(p);
+
 	if (IS_MMAPPED(self)) {
 		size_t extra = self->psize;
 		char *base = (char *)self - extra;
-- 
2.11.0



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fix undefined behavior in free
  2017-06-27 17:58 [PATCH] fix undefined behavior in free Alexander Monakov
@ 2017-07-04 21:11 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2017-07-04 21:11 UTC (permalink / raw)
  To: musl

On Tue, Jun 27, 2017 at 08:58:47PM +0300, Alexander Monakov wrote:
> ---
>  src/malloc/malloc.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c
> index 720fa696..ef4c7368 100644
> --- a/src/malloc/malloc.c
> +++ b/src/malloc/malloc.c
> @@ -463,14 +463,15 @@ copy_realloc:
>  
>  void free(void *p)
>  {
> -	struct chunk *self = MEM_TO_CHUNK(p);
> -	struct chunk *next;
> +	struct chunk *self, *next;
>  	size_t final_size, new_size, size;
>  	int reclaim=0;
>  	int i;
>  
>  	if (!p) return;
>  
> +	self = MEM_TO_CHUNK(p);
> +
>  	if (IS_MMAPPED(self)) {
>  		size_t extra = self->psize;
>  		char *base = (char *)self - extra;
> -- 
> 2.11.0

Thanks, applied

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-04 21:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-27 17:58 [PATCH] fix undefined behavior in free Alexander Monakov
2017-07-04 21:11 ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).