Skip to contentSkip to conversation

eal: fix cleanup on Windows

PATCH In review Thomas Monjalon 6 participants 8 messages Nov 8, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eal: fix cleanup on Windows

The memory allocated with _aligned_malloc()
must be released with _aligned_free() on Windows.

The POSIX free() was called in eal_lcore_var_cleanup(), called in rte_eal_cleanup(), and triggered a heap corruption:
exit status 3221226356 or signal 3221226228 SIGinvalid with MALLOC_PERTURB_=86

Fixes 5bce9bed67ad ("eal: add static per-lcore memory allocation facility")
---
 lib/eal/common/eal_common_lcore_var.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/common/eal_common_lcore_var.c +4 -1
index 0e9e8e4804..a1b2458839 100644
@@ -54,7 +54,6 @@ lcore_var_alloc(size_t size, size_t align)
 		current_buffer = _aligned_malloc(alloc_size, RTE_CACHE_LINE_SIZE);
 #else
 		current_buffer = aligned_alloc(RTE_CACHE_LINE_SIZE, alloc_size);
-
 #endif
 		RTE_VERIFY(current_buffer != NULL);
 
@@ -108,7 +107,11 @@ eal_lcore_var_cleanup(void)
 	while (current_buffer != NULL) {
 		struct lcore_var_buffer *prev = current_buffer->prev;
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+		_aligned_free(current_buffer);
+#else
 		free(current_buffer);
+#endif
 
 		current_buffer = prev;
 	}
Signature · 1 line
2.46.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Thomas Monjalon

The memory allocated with _aligned_malloc()
must be released with _aligned_free() on Windows.

The POSIX free() was called in eal_lcore_var_cleanup(), called in rte_eal_cleanup(), and triggered a heap corruption:
exit status 3221226356 or signal 3221226228 SIGinvalid with MALLOC_PERTURB_=86

Quoted 4 lines
Fixes 5bce9bed67ad ("eal: add static per-lcore memory allocation facility")
Signature · 1 line
David Marchand
Acked-by on v1 1/1
#3 lore raw
In reply to Thomas Monjalon

2024-11-08 14:08 (UTC+0100), Thomas Monjalon:

Quoted 8 lines

The memory allocated with _aligned_malloc()
must be released with _aligned_free() on Windows.

The POSIX free() was called in eal_lcore_var_cleanup(), called in rte_eal_cleanup(), and triggered a heap corruption:
exit status 3221226356 or signal 3221226228 SIGinvalid with MALLOC_PERTURB_=86

Quoted 4 lines
Fixes 5bce9bed67ad ("eal: add static per-lcore memory allocation facility")
Reviewed-by on v1 1/1
#4 lore raw
In reply to Thomas Monjalon
Quoted 4 lines · Thomas Monjalon

The memory allocated with _aligned_malloc()
must be released with _aligned_free() on Windows.

The POSIX free() was called in eal_lcore_var_cleanup(),

Referring to free() as a part of POSIX is true, but a bit misleading, since it's also standard C.

Quoted 26 lines

called in rte_eal_cleanup(), and triggered a heap corruption:
exit status 3221226356 or signal 3221226228 SIGinvalid with MALLOC_PERTURB_=86

Fixes 5bce9bed67ad ("eal: add static per-lcore memory allocation facility")
---
  lib/eal/common/eal_common_lcore_var.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
lib/eal/common/eal_common_lcore_var.c +0 -1
index 0e9e8e4804..a1b2458839 100644
@@ -54,7 +54,6 @@ lcore_var_alloc(size_t size, size_t align)
  		current_buffer = _aligned_malloc(alloc_size, RTE_CACHE_LINE_SIZE);
  #else
  		current_buffer = aligned_alloc(RTE_CACHE_LINE_SIZE, alloc_size);
-
  #endif
  		RTE_VERIFY(current_buffer != NULL);
 
@@ -108,7 +107,11 @@ eal_lcore_var_cleanup(void)
  	while (current_buffer != NULL) {

lib/eal/common/eal_common_lcore_var.c eal_lcore_var_cleanup(void) · line 117

Quoted 10 lines
lib/eal/common/eal_common_lcore_var.c +4 -0
  		struct lcore_var_buffer *prev = current_buffer->prev;
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+		_aligned_free(current_buffer);
+#else
  		free(current_buffer);
+#endif
 
  		current_buffer = prev;
  	}
author Applied
#5 lore raw

08/11/2024 16:43, Mattias Rönnblom:

Quoted 13 lines · Thomas Monjalon
Quoted 4 lines

The memory allocated with _aligned_malloc()
must be released with _aligned_free() on Windows.

The POSIX free() was called in eal_lcore_var_cleanup(),

Referring to free() as a part of POSIX is true, but a bit misleading, since it's also standard C.

Quoted 4 lines

called in rte_eal_cleanup(), and triggered a heap corruption:
exit status 3221226356 or signal 3221226228 SIGinvalid with MALLOC_PERTURB_=86

Quoted 6 lines
Quoted 4 lines
Fixes 5bce9bed67ad ("eal: add static per-lcore memory allocation facility")

Applied

#6 lore raw
In reply to Thomas Monjalon
Quoted 8 lines · On Fri, 8 Nov 2024 14:08:21 +0100 Thomas Monjalon <[email protected]> wrote:

The memory allocated with _aligned_malloc()
must be released with _aligned_free() on Windows.

The POSIX free() was called in eal_lcore_var_cleanup(), called in rte_eal_cleanup(), and triggered a heap corruption:
exit status 3221226356 or signal 3221226228 SIGinvalid with MALLOC_PERTURB_=86

Quoted 4 lines
Fixes 5bce9bed67ad ("eal: add static per-lcore memory allocation facility")

Is there anyway to use the function attributes to catch this at compile time (for Gcc builds).

#7 lore raw
Quoted 14 lines

From: Stephen Hemminger [mailto:[email protected]]
Sent: Friday, 8 November 2024 17.01

Quoted 8 lines · On Fri, 8 Nov 2024 14:08:21 +0100 Thomas Monjalon <[email protected]> wrote:

The memory allocated with _aligned_malloc()
must be released with _aligned_free() on Windows.

The POSIX free() was called in eal_lcore_var_cleanup(), called in rte_eal_cleanup(), and triggered a heap corruption:
exit status 3221226356 or signal 3221226228 SIGinvalid with MALLOC_PERTURB_=86

Quoted 8 lines
Quoted 1 line
Fixes 5bce9bed67ad ("eal: add static per-lcore memory allocation

facility")

Quoted 3 lines

Is there anyway to use the function attributes to catch this at compile time (for Gcc builds).

I took a look at it, and it boils down to building for a Windows environment, where RTE_EXEC_ENV_WINDOWS is defined, and then the alloc function attributes are disabled.