Commit b22d5d37 authored by Marcin Siodelski's avatar Marcin Siodelski

[3461] Corrected valgrind errors in the util library.

parent 0a00f963
...@@ -111,7 +111,9 @@ recv_fd(const int sock) { ...@@ -111,7 +111,9 @@ recv_fd(const int sock) {
// one returned previously, even if that one is not closed yet. So, // one returned previously, even if that one is not closed yet. So,
// we just re-number every one we get, so they are unique. // we just re-number every one we get, so they are unique.
int new_fd(dup(fd)); int new_fd(dup(fd));
int close_error(close(fd)); // Only call close() if the descriptor is valid. Otherwise return
// an error.
int close_error(fd >=0 ? close(fd) : -1);
if (close_error == -1 || new_fd == -1) { if (close_error == -1 || new_fd == -1) {
// We need to return an error, because something failed. But in case // We need to return an error, because something failed. But in case
// it was the previous close, we at least try to close the duped FD. // it was the previous close, we at least try to close the duped FD.
......
...@@ -59,7 +59,12 @@ TEST(MemorySegmentLocal, TestLocal) { ...@@ -59,7 +59,12 @@ TEST(MemorySegmentLocal, TestLocal) {
TEST(MemorySegmentLocal, TestTooMuchMemory) { TEST(MemorySegmentLocal, TestTooMuchMemory) {
auto_ptr<MemorySegment> segment(new MemorySegmentLocal()); auto_ptr<MemorySegment> segment(new MemorySegmentLocal());
EXPECT_THROW(segment->allocate(ULONG_MAX), bad_alloc); // Although it should be perfectly fine to use the ULONG_MAX
// instead of LONG_MAX as the size_t value should be unsigned,
// Valgrind appears to be using the signed value and hence the
// maximum positive value is LONG_MAX for Valgrind. But, this
// should be sufficient to test the "too much memory" conditions.
EXPECT_THROW(segment->allocate(LONG_MAX), bad_alloc);
} }
TEST(MemorySegmentLocal, TestBadDeallocate) { TEST(MemorySegmentLocal, TestBadDeallocate) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment