Fix cppcheck warning.
[awesomized/libmemcached] / clients / memcp.cc
index 59bd7478bb780a89d447d9c8949b1381c7342baa..f59e1d8c093f70df8eacae0954694911cbc963ad 100644 (file)
@@ -1,4 +1,5 @@
 /* LibMemcached
+ * Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
  * Copyright (C) 2006-2009 Brian Aker
  * All rights reserved.
  *
@@ -9,7 +10,7 @@
  *
  */
 
-#include "config.h"
+#include "mem_config.h"
 
 #include <cerrno>
 #include <climits>
@@ -30,7 +31,7 @@
 #include <unistd.h>
 
 
-#include <libmemcached/memcached.h>
+#include <libmemcached-1.0/memcached.h>
 
 #include "client_options.h"
 #include "utilities.h"
@@ -207,6 +208,7 @@ int main(int argc, char *argv[])
     if ((file_buffer_ptr= (char *)malloc(sizeof(char) * (size_t)sbuf.st_size)) == NULL)
     {
       std::cerr << "Error allocating file buffer(" << strerror(errno) << ")" << std::endl;
+      close(fd);
       exit(EXIT_FAILURE);
     }
 
@@ -214,12 +216,14 @@ int main(int argc, char *argv[])
     if ((read_length= ::read(fd, file_buffer_ptr, (size_t)sbuf.st_size)) == -1)
     {
       std::cerr << "Error while reading file " << file_buffer_ptr << " (" << strerror(errno) << ")" << std::endl;
+      close(fd);
       exit(EXIT_FAILURE);
     }
 
     if (read_length != sbuf.st_size)
     {
       std::cerr << "Failure while reading file. Read length was not equal to stat() length" << std::endl;
+      close(fd);
       exit(EXIT_FAILURE);
     }
 
@@ -246,6 +250,7 @@ int main(int argc, char *argv[])
     if (memcached_failed(rc))
     {
       std::cerr << "Error occrrured during memcached_set(): " << memcached_last_error_message(memc) << std::endl;
+      ::close(fd);
       exit_code= EXIT_FAILURE;
     }