#include <NeuralNetworks.h>
#include <sys/mman.h>
#include <new>
+#include <memory>
+#include "nnfw/std/memory.h"
#include "frontend/wrapper/memory.h"
int ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t offset,
return ANEURALNETWORKS_UNEXPECTED_NULL;
}
- *memory = new (std::nothrow) ANeuralNetworksMemory{size, protect, fd, offset};
- if (*memory == nullptr)
+ // Use unique pointer to avoid memory leak
+ std::unique_ptr<ANeuralNetworksMemory> memory_ptr =
+ nnfw::make_unique<ANeuralNetworksMemory>(size, protect, fd, offset);
+ if (memory_ptr == nullptr)
{
return ANEURALNETWORKS_OUT_OF_MEMORY;
}
+ *memory = memory_ptr.release();
return ANEURALNETWORKS_NO_ERROR;
}
#include <NeuralNetworks.h>
#include <sys/mman.h>
+#include <memory>
+#include "nnfw/std/memory.h"
#include "memory.h"
int ANeuralNetworksMemory_createFromFd(size_t size, int protect, int fd, size_t offset,
return ANEURALNETWORKS_UNEXPECTED_NULL;
}
- ANeuralNetworksMemory *memory_ptr = new ANeuralNetworksMemory{size, protect, fd, offset};
+ // Use unique pointer to avoid memory leak
+ std::unique_ptr<ANeuralNetworksMemory> memory_ptr =
+ nnfw::make_unique<ANeuralNetworksMemory>(size, protect, fd, offset);
if (memory_ptr == nullptr)
{
return ANEURALNETWORKS_OUT_OF_MEMORY;
}
- *memory = memory_ptr;
+ *memory = memory_ptr.release();
return ANEURALNETWORKS_NO_ERROR;
}