mirror of
https://github.com/ceph/ceph
synced 2025-01-02 09:02:34 +00:00
common,os,kv: Define aligned_free
Memory allocated using _aligned_malloc (Windows equivalent for posix_malloc) has to be deallocated by _aligned_free, otherwise leading to a crash. We'll define aligned_free as _aligned_free on Windows, using "free" on other platforms. Signed-off-by: Lucian Petrut <lpetrut@cloudbasesolutions.com>
This commit is contained in:
parent
d60bdd6b65
commit
6b087bb6f8
@ -124,7 +124,7 @@ static ceph::spinlock debug_lock;
|
||||
|
||||
static void operator delete(void *ptr) {
|
||||
raw_combined *raw = (raw_combined *)ptr;
|
||||
::free((void *)raw->data);
|
||||
aligned_free((void *)raw->data);
|
||||
}
|
||||
};
|
||||
|
||||
@ -176,7 +176,7 @@ static ceph::spinlock debug_lock;
|
||||
<< " l=" << l << ", align=" << align << bendl;
|
||||
}
|
||||
~raw_posix_aligned() override {
|
||||
::free(data);
|
||||
aligned_free(data);
|
||||
bdout << "raw_posix_aligned " << this << " free " << (void *)data << bendl;
|
||||
}
|
||||
raw* clone_empty() override {
|
||||
|
@ -292,19 +292,24 @@ int lchown(const char *path, uid_t owner, gid_t group);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// Use "aligned_free" when freeing memory allocated using posix_memalign or
|
||||
// _aligned_malloc. Using "free" will crash.
|
||||
#define aligned_free(ptr) _aligned_free(ptr)
|
||||
|
||||
// O_CLOEXEC is not defined on Windows. Since handles aren't inherited
|
||||
// with subprocesses unless explicitly requested, we'll define this
|
||||
// flag as a no-op.
|
||||
#define O_CLOEXEC 0
|
||||
#define SOCKOPT_VAL_TYPE char*
|
||||
|
||||
#else
|
||||
#else /* WIN32 */
|
||||
|
||||
#define SOCKOPT_VAL_TYPE void*
|
||||
|
||||
#define aligned_free(ptr) free(ptr)
|
||||
|
||||
#endif /* WIN32 */
|
||||
|
||||
#endif /* !CEPH_COMPAT_H */
|
||||
|
@ -370,7 +370,7 @@ public:
|
||||
if (type) {
|
||||
type->items -= n;
|
||||
}
|
||||
::free(p);
|
||||
aligned_free(p);
|
||||
}
|
||||
|
||||
void destroy(T* p) {
|
||||
|
@ -488,7 +488,7 @@ BinnedLRUCache::~BinnedLRUCache() {
|
||||
for (int i = 0; i < num_shards_; i++) {
|
||||
shards_[i].~BinnedLRUCacheShard();
|
||||
}
|
||||
free(shards_);
|
||||
aligned_free(shards_);
|
||||
}
|
||||
|
||||
CacheShard* BinnedLRUCache::GetShard(int shard) {
|
||||
|
@ -240,18 +240,18 @@ int FileJournal::_open_file(int64_t oldsize, blksize_t blksize,
|
||||
for (; (i + write_size) <= (uint64_t)max_size; i += write_size) {
|
||||
ret = ::pwrite(fd, static_cast<void*>(buf), write_size, i);
|
||||
if (ret < 0) {
|
||||
free(buf);
|
||||
aligned_free(buf);
|
||||
return -errno;
|
||||
}
|
||||
}
|
||||
if (i < (uint64_t)max_size) {
|
||||
ret = ::pwrite(fd, static_cast<void*>(buf), max_size - i, i);
|
||||
if (ret < 0) {
|
||||
free(buf);
|
||||
aligned_free(buf);
|
||||
return -errno;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
aligned_free(buf);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user