diff --git a/include/csptr/smart_ptr.h b/include/csptr/smart_ptr.h index 8087b99..e8c9cf2 100644 --- a/include/csptr/smart_ptr.h +++ b/include/csptr/smart_ptr.h @@ -70,7 +70,7 @@ CSPTR_INLINE void sfree_stack(void *ptr) { ({ \ struct s_tmp { \ CSPTR_SENTINEL_DEC \ - __typeof__(__typeof__(Type)[Length]) value; \ + __typeof__(Type) *value; \ f_destructor dtor; \ struct { \ const void *ptr; \ @@ -81,8 +81,12 @@ CSPTR_INLINE void sfree_stack(void *ptr) { __VA_ARGS__ \ }; \ void *var = smalloc(sizeof (Type), Length, Kind, ARGS_); \ - if (var != NULL) \ - memcpy(var, &args.value, sizeof (Type)); \ + if (var != NULL) { \ + if (args.value != NULL) \ + memcpy(var, args.value, sizeof (Type) * Length); \ + else \ + memset(var, 0, sizeof(Type) * Length); \ + } \ var; \ }) diff --git a/src/mman.c b/src/mman.c index 5df136c..ad6c3e8 100644 --- a/src/mman.c +++ b/src/mman.c @@ -136,7 +136,7 @@ CSPTR_INLINE static void dealloc_entry(s_meta *meta, void *ptr) { if (meta->kind & ARRAY) { s_meta_array *arr_meta = (void *) (meta + 1); for (size_t i = 0; i < arr_meta->nmemb; ++i) - meta->dtor((char *) ptr + arr_meta->size * i, user_meta); + meta->dtor((char *) ptr + arr_meta->size * i, arr_meta + 1); } else meta->dtor(ptr, user_meta); }