Skip to content

Commit

Permalink
fix(error): keep copy of error object for later references
Browse files Browse the repository at this point in the history
  • Loading branch information
dmansfield authored and mbroadst committed Aug 23, 2016
1 parent 526d924 commit 57e20f4
Show file tree
Hide file tree
Showing 14 changed files with 199 additions and 173 deletions.
153 changes: 77 additions & 76 deletions src/domain.cc

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ Error::Error(virErrorPtr error)
error_ = error;
}

Error::~Error()
{
virFreeError(error_);
}

Local<Value> Error::New(virErrorPtr error)
{
Nan::EscapableHandleScope scope;
Expand Down
1 change: 1 addition & 0 deletions src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Error : public Nan::ObjectWrap

private:
explicit Error(virErrorPtr error);
~Error();
static Nan::Persistent<Function> constructor;

static NAN_GETTER(Getter);
Expand Down
46 changes: 23 additions & 23 deletions src/hypervisor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ NLV_WORKER_EXECUTE(Hypervisor, Connect)
virConnectOpenAuth((const char*) hypervisor_->uri_.c_str(), &auth,
hypervisor_->readOnly_ ? VIR_CONNECT_RO : 0);
if (hypervisor_->handle_ == NULL)
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
}

NAN_METHOD(Hypervisor::Disconnect)
Expand All @@ -310,7 +310,7 @@ NLV_WORKER_EXECUTE(Hypervisor, Disconnect)
hypervisor_->ClearHandle();
// int result = virConnectClose(Handle());
// if (result == -1) {
// SetVirError(virGetLastError());
// SetVirError(virSaveLastError());
// return;
// }

Expand All @@ -323,7 +323,7 @@ NLV_WORKER_EXECUTE(Hypervisor, Disconnect)
NLV_WORKER_ASSERT_CONNECTION(); \
char *result = Accessor(Handle()); \
if (result == NULL) { \
SetVirError(virGetLastError()); \
SetVirError(virSaveLastError()); \
return; \
} \
data_ = result; \
Expand All @@ -335,7 +335,7 @@ NLV_WORKER_EXECUTE(Hypervisor, Disconnect)
NLV_WORKER_ASSERT_CONNECTION(); \
const char *result = Accessor(Handle()); \
if (result == NULL) { \
SetVirError(virGetLastError()); \
SetVirError(virSaveLastError()); \
return; \
} \
data_ = result; \
Expand All @@ -354,7 +354,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetSysInfo)
NLV_WORKER_ASSERT_CONNECTION();
char *result = virConnectGetSysinfo(Handle(), 0);
if (result == NULL) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand All @@ -376,7 +376,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetVersion)
unsigned long version;
int result = virConnectGetVersion(Handle(), &version);
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
} else if (result == 0 && version == 0) {
return;
Expand All @@ -400,7 +400,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetLibVirtVersion)
unsigned long version;
int result = virConnectGetLibVersion(Handle(), &version);
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand All @@ -418,7 +418,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetLibVirtVersion)
NLV_WORKER_ASSERT_CONNECTION(); \
int result = Accessor(Handle()); \
if (result == -1) { \
SetVirError(virGetLastError()); \
SetVirError(virSaveLastError()); \
return; \
} \
data_ = result; \
Expand Down Expand Up @@ -464,7 +464,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetMaxVcpus)
NLV_WORKER_ASSERT_CONNECTION();
int result = virConnectGetMaxVcpus(Handle(), type_.c_str());
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand Down Expand Up @@ -510,7 +510,7 @@ NLV_WORKER_EXECUTE(Hypervisor, SetKeepAlive)

int result = virConnectSetKeepAlive(Handle(), interval_, count_);
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand Down Expand Up @@ -554,7 +554,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetBaselineCPU)
delete [] cpus_;

if (result == NULL) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand Down Expand Up @@ -584,7 +584,7 @@ NLV_WORKER_EXECUTE(Hypervisor, CompareCPU)
NLV_WORKER_ASSERT_CONNECTION();
int result = virConnectCompareCPU(Handle(), (const char *)cpu_.c_str(), flags_);
if (result == VIR_CPU_COMPARE_ERROR) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand All @@ -596,7 +596,7 @@ NLV_WORKER_EXECUTE(Hypervisor, CompareCPU)
NLV_WORKER_ASSERT_CONNECTION() \
int count = CountMethod(Handle()); \
if (count == -1) { \
SetVirError(virGetLastError()); \
SetVirError(virSaveLastError()); \
return; \
} \
char **names = new char*[count]; \
Expand All @@ -606,7 +606,7 @@ NLV_WORKER_EXECUTE(Hypervisor, CompareCPU)
} \
int nameCount = ListMethod(Handle(), names, count); \
if (nameCount == -1) { \
SetVirError(virGetLastError()); \
SetVirError(virSaveLastError()); \
delete [] names; \
return; \
} \
Expand All @@ -622,7 +622,7 @@ NLV_WORKER_EXECUTE(Hypervisor, CompareCPU)
NLV_WORKER_ASSERT_CONNECTION() \
int count = CountMethod(Handle()); \
if (count == -1) { \
SetVirError(virGetLastError()); \
SetVirError(virSaveLastError()); \
return; \
} \
int *elements = new int[count]; \
Expand All @@ -633,7 +633,7 @@ NLV_WORKER_EXECUTE(Hypervisor, CompareCPU)
} \
int elementCount = ListMethod(Handle(), elements, count); \
if (elementCount == -1) { \
SetVirError(virGetLastError()); \
SetVirError(virSaveLastError()); \
return; \
} \
for (int i = 0; i < elementCount; ++i) { \
Expand Down Expand Up @@ -744,7 +744,7 @@ NLV_WORKER_EXECUTE(Hypervisor, ListNodeDevices)
virNodeNumOfDevices(Handle(), (const char *) capability_.c_str(), flags);

if (num_devices == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand All @@ -758,7 +758,7 @@ NLV_WORKER_EXECUTE(Hypervisor, ListNodeDevices)
virNodeListDevices(Handle(), (const char *)capability_.c_str(), names, num_devices, flags);
if (num_devices == -1) {
free(names);
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand All @@ -776,7 +776,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetNodeSecurityModel)
NLV_WORKER_ASSERT_CONNECTION();
int result = virNodeGetSecurityModel(Handle(), &securityModel_);
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}
}
Expand All @@ -803,7 +803,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetNodeInfo)
NLV_WORKER_ASSERT_CONNECTION();
int result = virNodeGetInfo(Handle(), &info_);
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}
}
Expand Down Expand Up @@ -832,7 +832,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetNodeFreeMemory)
NLV_WORKER_ASSERT_CONNECTION();
unsigned long long result = virNodeGetFreeMemory(Handle());
if (result == 0) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand Down Expand Up @@ -865,7 +865,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetNodeMemoryStats)
result = virNodeGetMemoryStats(Handle(), cellNum_, &info_[0], &nparams, flags_);
}
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}
}
Expand Down Expand Up @@ -918,7 +918,7 @@ NLV_WORKER_EXECUTE(Hypervisor, GetNodeCellsFreeMemory)
virNodeGetCellsFreeMemory(Handle(), results, startCell_, maxCells_);
if (cells == -1) {
free(results);
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand Down
16 changes: 8 additions & 8 deletions src/interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ NLV_WORKER_EXECUTE(Interface, Start)
unsigned int flags = 0;
int result = virInterfaceCreate(Handle(), flags);
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand All @@ -63,7 +63,7 @@ NLV_WORKER_EXECUTE(Interface, Stop)
unsigned int flags = 0;
int result = virInterfaceDestroy(Handle(), flags);
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand All @@ -76,7 +76,7 @@ NLV_WORKER_EXECUTE(Interface, Define)
unsigned int flags = 0;
lookupHandle_ = virInterfaceDefineXML(parent_->handle_, value_.c_str(), flags);
if (lookupHandle_ == NULL) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}
}
Expand All @@ -87,7 +87,7 @@ NLV_WORKER_EXECUTE(Interface, Undefine)
NLV_WORKER_ASSERT_INTERFACE();
int result = virInterfaceUndefine(Handle());
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand Down Expand Up @@ -146,7 +146,7 @@ NLV_WORKER_EXECUTE(Interface, GetName)
NLV_WORKER_ASSERT_INTERFACE();
const char *result = virInterfaceGetName(Handle());
if (result == NULL) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand All @@ -159,7 +159,7 @@ NLV_WORKER_EXECUTE(Interface, GetMacAddress)
NLV_WORKER_ASSERT_INTERFACE();
const char *result = virInterfaceGetMACString(Handle());
if (result == NULL) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand All @@ -172,7 +172,7 @@ NLV_WORKER_EXECUTE(Interface, IsActive)
NLV_WORKER_ASSERT_INTERFACE();
int result = virInterfaceIsActive(Handle());
if (result == -1) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand All @@ -186,7 +186,7 @@ NLV_WORKER_EXECUTE(Interface, ToXml)
unsigned int flags = 0;
char *result = virInterfaceGetXMLDesc(Handle(), flags);
if (result == NULL) {
SetVirError(virGetLastError());
SetVirError(virSaveLastError());
return;
}

Expand Down
Loading

0 comments on commit 57e20f4

Please sign in to comment.