diff --git a/CMakeLists.txt b/CMakeLists.txt
index 311559ddc5d27b232506953ac6743d9612e68c94..1e0a8eae8689f8f9119f26156674b6224518638c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,31 +31,18 @@ set(CMAKE_CXX_FLAGS "-fPIC -pedantic -Wall -Wextra -Werror -Wno-unused-parameter
 # to be tested once we have a stable compilation on CC7:
 #-Wno-unused-parameter -Wlogical-op -Wfloat-equal -Wdeclaration-after- statement -Wundef -Wno-endif-labels -Wshadow -Wunsafe-loop- optimizations -Wpointer-arith -Wbad-function-cast -Wcast-align -Wwrite- strings -Wconversion -Wmissing-field-initializers -Wredundant-decls -Wnested-externs -Wunreachable-code -Winline -Wvariadic-macros -Wtraditional -Wmissing-prototypes -Wmissing-declarations -Wold-style- definition -Wc++-compat -Wstrict-prototypes -Wpadded -Wcast-qual -Wnon-virtual-dtor -Wlogical-op -Wmissing-declarations -Wsign-conversion -Wredundant-decls -Wold-style-cast -Wshadow
 
-# Explicitly setting the C and C++ compiler flags for the RelWithDebInfo build
-# in order to prevent the -O2 flag from being used.
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g")
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g")
-
 set (BUILD_CMDLINE_ONLY FALSE)
 
 execute_process(
   COMMAND ${CMAKE_C_COMPILER} -dumpversion
   OUTPUT_VARIABLE GCC_VERSION)
 
-if (CMAKE_COMPILER_IS_GNUCC)
-  message(STATUS "GCC VERSION ${GCC_VERSION}")
-  if (GCC_VERSION VERSION_GREATER_EQUAL 7.0)
-    message(STATUS "Detected gcc > 7.0 - switching on support for c++17")
-    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
-  elseif (GCC_VERSION VERSION_EQUAL 4.4.7)
-    message(STATUS "Detected gcc = 4.4.7 - build cmdline only with c++0x")
-    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
-    set (BUILD_CMDLINE_ONLY TRUE)
-  elseif (GCC_VERSION VERSION_GREATER 4.4.7)
-    message(STATUS "Detected gcc > 4.4.7 - switching on support for c++1y")
-    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y")
-  endif ()
-endif ()
+message(STATUS "Setting support for c++17")
+set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
+
+if (NOT CMAKE_BUILD_TYPE)
+  set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "" FORCE)
+endif()
 
 # CTA continue using the old ABI, so we should force it. This command only works on cmake3,
 # so we should update the requeriments of CMakeLists
@@ -63,11 +50,6 @@ endif ()
 #      https://docs.ceph.com/en/latest/dev/cxx/
 add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)
 
-set (GCC_VERSION_GE_4_8_0 FALSE)
-if (CMAKE_COMPILER_IS_GNUCC AND ((GCC_VERSION VERSION_GREATER 4.8.0) OR (GCC_VERSION VERSION_EQUAL 4.8.0)))
-  set (GCC_VERSION_GE_4_8_0 TRUE)
-endif (CMAKE_COMPILER_IS_GNUCC AND ((GCC_VERSION VERSION_GREATER 4.8.0) OR (GCC_VERSION VERSION_EQUAL 4.8.0)))
-
 # To enable logging for testing purposes set -DENABLE_STDOUT_LOGGING=1
 if (ENABLE_STDOUT_LOGGING)
   add_definitions (-DSTDOUT_LOGGING)
@@ -126,14 +108,6 @@ ELSE(DEFINED PackageOnly)
   # OCCI support is on by default
   set (OCCI_SUPPORT ON)
 
-  # Switch OCCI support off if using gcc 5.1 or higher
-  #if (CMAKE_COMPILER_IS_GNUCC)
-  #  if (GCC_VERSION VERSION_GREATER 5.0)
-  #    message (STATUS "Detected gcc >= 5.1 - Switching off OCCI support")
-  #    set (OCCI_SUPPORT OFF)
-  #  endif (GCC_VERSION VERSION_GREATER 5.0)
-  #endif (CMAKE_COMPILER_IS_GNUCC)
-
   if (OCCI_SUPPORT)
     find_package (oracle-instantclient REQUIRED)
   endif (OCCI_SUPPORT)
diff --git a/catalogue/CreateAdminUserCmdLineArgsTest.cpp b/catalogue/CreateAdminUserCmdLineArgsTest.cpp
index e1a85fee3f51bf404893700be99e06758989f8aa..175017b67eeffe9101d3571babff586f6d001c8a 100644
--- a/catalogue/CreateAdminUserCmdLineArgsTest.cpp
+++ b/catalogue/CreateAdminUserCmdLineArgsTest.cpp
@@ -37,12 +37,12 @@ protected:
   /**
    * Creates a duplicate string using the new operator.
    */
-  char *dupString(const char *str) {
-    const size_t len = strlen(str);
-    char *duplicate = new char[len+1];
-    strncpy(duplicate, str, len);
-    duplicate[len] = '\0';
-    return duplicate;
+  char *dupString(const std::string &str) {
+    const int len = str.size();
+    char *copy = new char[len + 1];
+    std::copy(str.begin(), str.end(), copy);
+    copy[len] = '\0';
+    return copy;
   }
 
   virtual void SetUp() {
diff --git a/catalogue/CreateSchemaCmdLineArgsTest.cpp b/catalogue/CreateSchemaCmdLineArgsTest.cpp
index 6898da14921e299999c0c1fdeb52d1188e887609..5542fc21eb2c31d0869ca86b1933e7d95b7cb613 100644
--- a/catalogue/CreateSchemaCmdLineArgsTest.cpp
+++ b/catalogue/CreateSchemaCmdLineArgsTest.cpp
@@ -38,12 +38,12 @@ protected:
   /**
    * Creates a duplicate string using the new operator.
    */
-  char *dupString(const char *str) {
-    const size_t len = strlen(str);
-    char *duplicate = new char[len+1];
-    strncpy(duplicate, str, len);
-    duplicate[len] = '\0';
-    return duplicate;
+  char *dupString(const std::string &str) {
+    const int len = str.size();
+    char *copy = new char[len + 1];
+    std::copy(str.begin(), str.end(), copy);
+    copy[len] = '\0';
+    return copy;
   }
 
   virtual void SetUp() {
diff --git a/catalogue/DropSchemaCmdLineArgsTest.cpp b/catalogue/DropSchemaCmdLineArgsTest.cpp
index 0cf7df792c557f90690fd2274acaa6ed376b69d4..a9a6dc11953919da70203cc903e7383d80069a6b 100644
--- a/catalogue/DropSchemaCmdLineArgsTest.cpp
+++ b/catalogue/DropSchemaCmdLineArgsTest.cpp
@@ -38,12 +38,12 @@ protected:
   /**
    * Creates a duplicate string using the new operator.
    */
-  char *dupString(const char *str) {
-    const size_t len = strlen(str);
-    char *duplicate = new char[len+1];
-    strncpy(duplicate, str, len);
-    duplicate[len] = '\0';
-    return duplicate;
+  char *dupString(const std::string &str) {
+    const int len = str.size();
+    char *copy = new char[len + 1];
+    std::copy(str.begin(), str.end(), copy);
+    copy[len] = '\0';
+    return copy;
   }
 
   virtual void SetUp() {
diff --git a/catalogue/PollDatabaseCmdLineArgsTest.cpp b/catalogue/PollDatabaseCmdLineArgsTest.cpp
index c1911a1bf43b976660fba3e88d448e8fc9667711..89558abbe105eecc981e252439a8db1c36228746 100644
--- a/catalogue/PollDatabaseCmdLineArgsTest.cpp
+++ b/catalogue/PollDatabaseCmdLineArgsTest.cpp
@@ -38,12 +38,12 @@ protected:
   /**
    * Creates a duplicate string using the new operator.
    */
-  char *dupString(const char *str) {
-    const size_t len = strlen(str);
-    char *duplicate = new char[len+1];
-    strncpy(duplicate, str, len);
-    duplicate[len] = '\0';
-    return duplicate;
+  char *dupString(const std::string &str) {
+    const int len = str.size();
+    char *copy = new char[len + 1];
+    std::copy(str.begin(), str.end(), copy);
+    copy[len] = '\0';
+    return copy;
   }
 
   virtual void SetUp() {
diff --git a/catalogue/VerifySchemaCmdLineArgsTest.cpp b/catalogue/VerifySchemaCmdLineArgsTest.cpp
index d745c9bdbef8e67fa1635d18f57f3c5254a4fd5a..18ffe5bfe7a787bcae716cda2a98997b759e93ce 100644
--- a/catalogue/VerifySchemaCmdLineArgsTest.cpp
+++ b/catalogue/VerifySchemaCmdLineArgsTest.cpp
@@ -38,12 +38,12 @@ protected:
   /**
    * Creates a duplicate string using the new operator.
    */
-  char *dupString(const char *str) {
-    const size_t len = strlen(str);
-    char *duplicate = new char[len+1];
-    strncpy(duplicate, str, len);
-    duplicate[len] = '\0';
-    return duplicate;
+  char *dupString(const std::string &str) {
+    const int len = str.size();
+    char *copy = new char[len + 1];
+    std::copy(str.begin(), str.end(), copy);
+    copy[len] = '\0';
+    return copy;
   }
 
   virtual void SetUp() {
diff --git a/common/checksum/ChecksumBlob.cpp b/common/checksum/ChecksumBlob.cpp
index 00d7191bc7970b1a472ce8c0db7fb513d901552a..8087672160ad368920ec38fe3695d8c92f6a5f19 100644
--- a/common/checksum/ChecksumBlob.cpp
+++ b/common/checksum/ChecksumBlob.cpp
@@ -25,7 +25,7 @@ namespace checksum {
 
 void ChecksumBlob::insert(ChecksumType type, const std::string &value) {
   // Validate the length of the checksum
-  size_t expectedLength;
+  size_t expectedLength = 0;
   switch(type) {
     case NONE:       expectedLength = 0;  break;
     case ADLER32:
diff --git a/eos_cta/CMakeLists.txt b/eos_cta/CMakeLists.txt
index 69eeebab525c3274f0fdeda14847785ceade5c17..b10e0c446887766787e91ddbb7515e8364868106 100644
--- a/eos_cta/CMakeLists.txt
+++ b/eos_cta/CMakeLists.txt
@@ -42,12 +42,6 @@ set_source_files_properties(
 
 foreach(PROTO_SRC ${ProtoSourcesEosCta} ${ProtoSourcesMigration} ${ProtoGrpcSourcesMigration})
   set_property(SOURCE ${PROTO_SRC} PROPERTY COMPILE_FLAGS " -Wno-missing-field-initializers -fPIC -Wno-narrowing -Wno-implicit-fallthrough")
-  # Add -Wno-narrowing -Wno-implicit-fallthrough compiler flags if using gcc version 7 or greater
-  if(CMAKE_COMPILER_IS_GNUCC)
-    if(GCC_VERSION VERSION_EQUAL 7 OR GCC_VERSION VERSION_GREATER 7)
-      set_property(SOURCE ${PROTO_SRC} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-narrowing -Wno-implicit-fallthrough")
-    endif(GCC_VERSION VERSION_EQUAL 7 OR GCC_VERSION VERSION_GREATER 7)
-  endif(CMAKE_COMPILER_IS_GNUCC)
 endforeach(PROTO_SRC)
 
 add_library(XrdSsiPbEosCta ${ProtoSourcesEosCta})
diff --git a/mediachanger/DismountCmdLineTest.cpp b/mediachanger/DismountCmdLineTest.cpp
index ba32b2e3eb25d236739c9a1887f5c6593fe5ee20..30f0164be02c84910247271860289638934522b1 100644
--- a/mediachanger/DismountCmdLineTest.cpp
+++ b/mediachanger/DismountCmdLineTest.cpp
@@ -39,12 +39,12 @@ protected:
   /**
    * Creates a duplicate string using the new operator.
    */
-  char *dupString(const char *str) {
-    const size_t len = strlen(str);
-    char *duplicate = new char[len+1];
-    strncpy(duplicate, str, len);
-    duplicate[len] = '\0';
-    return duplicate;
+  char *dupString(const std::string &str) {
+    const int len = str.size();
+    char *copy = new char[len + 1];
+    std::copy(str.begin(), str.end(), copy);
+    copy[len] = '\0';
+    return copy;
   }
 
   virtual void SetUp() {
@@ -71,7 +71,7 @@ TEST_F(cta_mediachanger_DismountCmdLineTest, copy_constructor) {
   Argcv *args= new Argcv();
   m_argsList.push_back(args);
   args->argc = 3;
-  args->argv = new char *[4]; 
+  args->argv = new char *[4];
   args->argv[0] = dupString("cta-mediachanger-dismount");
   args->argv[1] = dupString("vid");
   args->argv[2] = dupString("smc1");
@@ -98,7 +98,7 @@ TEST_F(cta_mediachanger_DismountCmdLineTest, assignment) {
   Argcv *args1= new Argcv();
   m_argsList.push_back(args1);
   args1->argc = 3;
-  args1->argv = new char *[4]; 
+  args1->argv = new char *[4];
   args1->argv[0] = dupString("cta-mediachanger-dismount");
   args1->argv[1] = dupString("vid");
   args1->argv[2] = dupString("smc1");
@@ -113,7 +113,7 @@ TEST_F(cta_mediachanger_DismountCmdLineTest, assignment) {
   Argcv *args2= new Argcv();
   m_argsList.push_back(args2);
   args2->argc = 3;
-  args2->argv = new char *[4]; 
+  args2->argv = new char *[4];
   args2->argv[0] = dupString("cta-mediachanger-dismount");
   args2->argv[1] = dupString("vid");
   args2->argv[2] = dupString("smc2");
@@ -140,16 +140,16 @@ TEST_F(cta_mediachanger_DismountCmdLineTest, assignment) {
 
 TEST_F(cta_mediachanger_DismountCmdLineTest, scsi) {
   using namespace cta::mediachanger;
-  
+
   Argcv *args = new Argcv();
   m_argsList.push_back(args);
   args->argc = 3;
-  args->argv = new char *[4]; 
+  args->argv = new char *[4];
   args->argv[0] = dupString("cta-mediachanger-dismount");
   args->argv[1] = dupString("vid");
   args->argv[2] = dupString("smc1");
   args->argv[3] = NULL;
-  
+
   std::unique_ptr<DismountCmdLine> cmdLine;
   ASSERT_NO_THROW(cmdLine.reset(new DismountCmdLine(args->argc, args->argv)));
 
diff --git a/mediachanger/MountCmdLineTest.cpp b/mediachanger/MountCmdLineTest.cpp
index 343a5d2a6ea5065cd39afaa0b09efbd7863876cf..c427abae03bddcd468075b30def5061555732679 100644
--- a/mediachanger/MountCmdLineTest.cpp
+++ b/mediachanger/MountCmdLineTest.cpp
@@ -39,12 +39,12 @@ protected:
   /**
    * Creates a duplicate string using the new operator.
    */
-  char *dupString(const char *str) {
-    const size_t len = strlen(str);
-    char *duplicate = new char[len+1];
-    strncpy(duplicate, str, len);
-    duplicate[len] = '\0';
-    return duplicate;
+  char *dupString(const std::string &str) {
+    const int len = str.size();
+    char *copy = new char[len + 1];
+    std::copy(str.begin(), str.end(), copy);
+    copy[len] = '\0';
+    return copy;
   }
 
   virtual void SetUp() {
@@ -119,7 +119,7 @@ TEST_F(cta_mediachanger_MountCmdLineTest, assignment) {
   args2->argv[1] = dupString("vid");
   args2->argv[2] = dupString("smc2");
   args2->argv[3] = NULL;
-  
+
   MountCmdLine cmdLine2(args2->argc, args2->argv);
   ASSERT_FALSE(cmdLine2.getHelp());
   ASSERT_FALSE(cmdLine2.getDebug());
diff --git a/mediachanger/castorrmc/rmc/CMakeLists.txt b/mediachanger/castorrmc/rmc/CMakeLists.txt
index 92ab8c916c314ad917d3e71ac5ec6a9dbb88a321..0c7079c98c1140e5d39fd05276593fe0122addb0 100644
--- a/mediachanger/castorrmc/rmc/CMakeLists.txt
+++ b/mediachanger/castorrmc/rmc/CMakeLists.txt
@@ -28,12 +28,8 @@ set (RMCD_SRC_FILES
   spectra_like_libs.c
 )
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  # Add -Wno-format-overflow compiler flag if using gcc version 7 or greater
-  if (GCC_VERSION VERSION_EQUAL 7 OR GCC_VERSION VERSION_GREATER 7)
-    set_property(SOURCE rmc_send_scsi_cmd.c APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-format-overflow")
-  endif (GCC_VERSION VERSION_EQUAL 7 OR GCC_VERSION VERSION_GREATER 7)
-endif(CMAKE_COMPILER_IS_GNUCC)
+# Add -Wno-format-overflow compiler flag
+set_property(SOURCE rmc_send_scsi_cmd.c APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-format-overflow")
 
 add_executable(cta-rmcd ${RMCD_SRC_FILES})
 target_link_libraries(cta-rmcd ctarmccommon)
diff --git a/objectstore/RootEntry.cpp b/objectstore/RootEntry.cpp
index 8600858c4ce8a9b8455c3aea370eb45b2fc855d3..b89ee61e2ff17731be60b0fbb5624808edad3e5e 100644
--- a/objectstore/RootEntry.cpp
+++ b/objectstore/RootEntry.cpp
@@ -857,13 +857,13 @@ void RootEntry::removeRepackQueueAndCommit(common::dataStructures::RepackQueueTy
   checkPayloadWritable();
   // find the address of the repack queue object
   try {
-    bool hasQueue;
+    bool hasQueue = false;
     switch (queueType) {
-    case common::dataStructures::RepackQueueType::Pending:
-      hasQueue = m_payload.has_repackrequestspendingqueuepointer();
-      break;
-    case common::dataStructures::RepackQueueType::ToExpand:
-      hasQueue = m_payload.has_repackrequeststoexpandqueuepointer();
+      case common::dataStructures::RepackQueueType::Pending:
+        hasQueue = m_payload.has_repackrequestspendingqueuepointer();
+        break;
+      case common::dataStructures::RepackQueueType::ToExpand:
+        hasQueue = m_payload.has_repackrequeststoexpandqueuepointer();
     }
     if (!hasQueue) {
       throw NoSuchRepackQueue("In RootEntry::removeRepackQueueAndCommit: trying to remove non-existing repack queue");
diff --git a/scheduler/CMakeLists.txt b/scheduler/CMakeLists.txt
index f155d33d04761adbac7f8612602ca67da4a89b53..38e1bcace0c60f835e79993f1dd4075313231a47 100644
--- a/scheduler/CMakeLists.txt
+++ b/scheduler/CMakeLists.txt
@@ -63,14 +63,9 @@ add_library (ctaschedulerunittests SHARED
 set_property(TARGET ctaschedulerunittests PROPERTY SOVERSION "${CTA_SOVERSION}")
 set_property(TARGET ctaschedulerunittests PROPERTY   VERSION "${CTA_LIBVERSION}")
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  # Add -Wno-unused-function compiler flag if using gcc version 6 or greater
-  if (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6)
-    set_property(SOURCE OStoreDB/OStoreDBTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function")
-    set_property(SOURCE SchedulerDatabaseTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function")
-    set_property(SOURCE SchedulerTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function")
-  endif (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6)
-endif(CMAKE_COMPILER_IS_GNUCC)
+set_property(SOURCE OStoreDB/OStoreDBTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function")
+set_property(SOURCE SchedulerDatabaseTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function")
+set_property(SOURCE SchedulerTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function")
 
 target_link_libraries (ctaschedulerunittests
   ctascheduler)
diff --git a/tapeserver/castor/tape/tapeserver/SCSI/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/SCSI/CMakeLists.txt
index 63e2e74ae95e8f756bdc2bef242aa79713854a88..a296bbc496ce5edf8d4297d7d0cf18f36b3f460d 100644
--- a/tapeserver/castor/tape/tapeserver/SCSI/CMakeLists.txt
+++ b/tapeserver/castor/tape/tapeserver/SCSI/CMakeLists.txt
@@ -16,17 +16,6 @@ cmake_minimum_required (VERSION 3.17)
 
 include_directories(${CMAKE_SOURCE_DIR}/tapeserver)
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  if(GCC_VERSION_GE_4_8_0)
-    set_property(SOURCE Device.cpp
-      PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-    set_property(SOURCE DeviceTest.cpp
-      PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-    set_property(SOURCE StructuresTest.cpp
-      PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-  endif(GCC_VERSION_GE_4_8_0)
-endif(CMAKE_COMPILER_IS_GNUCC)
-
 add_library(SCSI Device.cpp Structures.cpp Constants.cpp Exception.cpp)
 
 add_library(ctatapeserverscsiunittests SHARED
diff --git a/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt
index 17c23ce4f062cbd1ecb97a0c722b1106b8efc86d..d1e6231499331be928a643767d0b007bd4412495 100644
--- a/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt
+++ b/tapeserver/castor/tape/tapeserver/daemon/CMakeLists.txt
@@ -48,30 +48,8 @@ set(CTATAPESERVERDAEMON_LIBRARY_SRCS
   TapeWriteSingleThread.cpp
   TapeWriteTask.cpp)
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  if(GCC_VERSION_GE_4_8_0)
-    foreach(CTATAPESERVERDAEMON_LIBRARY_SRC
-       ${CTATAPESERVERDAEMON_LIBRARY_SRCS}
-       CatalogueTest.cpp
-       DataTransferSessionTest.cpp
-       DiskReadTaskTest.cpp
-       DiskWriteTaskTest.cpp
-       DiskWriteTaskTest.cpp
-       DiskWriteThreadPoolTest.cpp
-       MigrationReportPackerTest.cpp
-       ProcessForkerProxyDummy.cpp
-       ProcessForkerTest.cpp
-       RecallTaskInjectorTest.cpp)
-      set_property(SOURCE ${CTATAPESERVERDAEMON_LIBRARY_SRC}
-        PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-    endforeach(CTATAPESERVERDAEMON_LIBRARY_SRC)
-
-    # Add -Wno-unused-function compiler flag if using gcc version 6 or greater
-    if (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6)
-      set_property(SOURCE DataTransferSessionTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function")
-    endif (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6)
-  endif(GCC_VERSION_GE_4_8_0)
-endif(CMAKE_COMPILER_IS_GNUCC)
+# Add -Wno-unused-function compiler flag
+set_property(SOURCE DataTransferSessionTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function")
 
 add_library(ctaTapeServerDaemon
   ${CTATAPESERVERDAEMON_LIBRARY_SRCS})
@@ -94,13 +72,6 @@ add_library(ctatapeserverdaemonunittests SHARED
 set_property(TARGET ctatapeserverdaemonunittests PROPERTY SOVERSION "${CTA_SOVERSION}")
 set_property(TARGET ctatapeserverdaemonunittests PROPERTY   VERSION "${CTA_LIBVERSION}")
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  # Add -Wno-unused-function compiler flag if using gcc version 6 or greater
-  if (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6)
-    set_property(SOURCE RecallReportPackerTest.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-unused-function")
-  endif (GCC_VERSION VERSION_EQUAL 6 OR GCC_VERSION VERSION_GREATER 6)
-endif(CMAKE_COMPILER_IS_GNUCC)
-
 target_link_libraries(ctatapeserverdaemonunittests
   ctamessagesutils)
   #ctaschedulerutils
diff --git a/tapeserver/castor/tape/tapeserver/drive/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/drive/CMakeLists.txt
index 69e7729321c92fdbc9cde07b33eaa0244554c4c8..9b9e2ac54d687680b37abbb333d8907247e4062f 100644
--- a/tapeserver/castor/tape/tapeserver/drive/CMakeLists.txt
+++ b/tapeserver/castor/tape/tapeserver/drive/CMakeLists.txt
@@ -20,25 +20,9 @@ set(TAPEDRIVE_LIBRARY_SRCS
   DriveGeneric.cpp
   FakeDrive.cpp)
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  if(GCC_VERSION_GE_4_8_0)
-    foreach(TAPEDRIVE_LIBRARY_SRC ${TAPEDRIVE_LIBRARY_SRCS})
-      set_property(SOURCE ${TAPEDRIVE_LIBRARY_SRC}
-        PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-    endforeach(TAPEDRIVE_LIBRARY_SRC)
-  endif(GCC_VERSION_GE_4_8_0)
-endif(CMAKE_COMPILER_IS_GNUCC)
-
 add_library(TapeDrive ${TAPEDRIVE_LIBRARY_SRCS})
 target_link_libraries(TapeDrive SCSI ctatapedaemon)
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  if(GCC_VERSION_GE_4_8_0)
-    set_property(SOURCE TapeDriveReadWriteTest.cpp
-      PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-  endif(GCC_VERSION_GE_4_8_0)
-endif(CMAKE_COMPILER_IS_GNUCC)
-
 add_executable(TapeDriveReadWriteTest
   TapeDriveReadWriteTest.cpp)
 target_link_libraries(TapeDriveReadWriteTest
@@ -52,13 +36,6 @@ target_link_libraries(TapeDriveReadWriteTest
   gtest
   pthread)
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  if(GCC_VERSION_GE_4_8_0)
-    set_property(SOURCE DriveTest.cpp
-      PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-  endif(GCC_VERSION_GE_4_8_0)
-endif(CMAKE_COMPILER_IS_GNUCC)
-
 add_library(ctatapeserverdriveunittests SHARED
   DriveTest.cpp)
 set_property(TARGET ctatapeserverdriveunittests PROPERTY SOVERSION "${CTA_SOVERSION}")
diff --git a/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp b/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp
index 793a774999866eafa98064bfda5f77b603195c4e..8cc054552870821227e5f2df9fbd45d4775f7aa9 100644
--- a/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp
+++ b/tapeserver/castor/tape/tapeserver/drive/DriveGeneric.cpp
@@ -641,6 +641,7 @@ drive::LBPInfo drive::DriveGeneric::getLBPInfo() {
 //------------------------------------------------------------------------------
 // Encryption interface
 //------------------------------------------------------------------------------
+#pragma GCC diagnostic ignored "-Wstringop-truncation"
 void drive::DriveGeneric::setEncryptionKey(const std::string &encryption_key) {
   if(!isEncryptionCapEnabled())
     throw cta::exception::Exception("In DriveGeneric::setEncryptionKey: Tried to enable encryption on drive "
diff --git a/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt
index 50bb447a2b5b09f2bc596772e6229c1cc8d693a5..f434743add155620d03ff3c671fd84b4c250c106 100644
--- a/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt
+++ b/tapeserver/castor/tape/tapeserver/file/CMakeLists.txt
@@ -24,22 +24,6 @@ set(TAPESERVER_FILE_LIBRARY_SRCS
   File.cpp
   Structures.cpp)
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  if(GCC_VERSION_GE_4_8_0)
-    foreach(TAPESERVER_FILE_LIBRARY_SRC ${TAPESERVER_FILE_LIBRARY_SRCS})
-      set_property(SOURCE ${TAPESERVER_FILE_LIBRARY_SRC}
-        PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-    endforeach(TAPESERVER_FILE_LIBRARY_SRC)
-  endif(GCC_VERSION_GE_4_8_0)
-endif(CMAKE_COMPILER_IS_GNUCC)
-
-if(CMAKE_COMPILER_IS_GNUCC)
-  if(GCC_VERSION_GE_4_8_0)
-    set_property(SOURCE BasicReadWriteTest.cpp
-      PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-  endif(GCC_VERSION_GE_4_8_0)
-endif(CMAKE_COMPILER_IS_GNUCC)
-
 add_executable(BasicReadWriteTest
   BasicReadWriteTest.cpp)
 
@@ -56,17 +40,6 @@ target_link_libraries(BasicReadWriteTest
 add_library(File
   ${TAPESERVER_FILE_LIBRARY_SRCS})
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  if(GCC_VERSION_GE_4_8_0)
-    set_property(SOURCE StructuresTest.cpp
-      PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-    set_property(SOURCE FileTest.cpp
-      PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-    set_property(SOURCE CryptoPPTest.cpp
-      PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-  endif(GCC_VERSION_GE_4_8_0)
-endif(CMAKE_COMPILER_IS_GNUCC)
-
 add_library(ctatapeserverfileunittests SHARED
   StructuresTest.cpp
   FileTest.cpp
diff --git a/tapeserver/castor/tape/tapeserver/file/FileTest.cpp b/tapeserver/castor/tape/tapeserver/file/FileTest.cpp
index 457d5ed5dfa1a600e56a52c511ad157cd1312f04..6d44dd74313d240012552e1e836dfe9174a25d49 100644
--- a/tapeserver/castor/tape/tapeserver/file/FileTest.cpp
+++ b/tapeserver/castor/tape/tapeserver/file/FileTest.cpp
@@ -95,18 +95,19 @@ namespace unitTests {
    
   TEST_F(castorTapeFileTest, throwsWhenUsingSessionTwice) {
     const std::string testString("Hello World!");
-    castor::tape::tapeFile::WriteSession *ws;
-    ASSERT_NO_THROW(ws = new castor::tape::tapeFile::WriteSession(d, volInfo, 0, true, false));
+    std::unique_ptr<castor::tape::tapeFile::WriteSession> ws;
+    ASSERT_NO_THROW(ws = std::make_unique<castor::tape::tapeFile::WriteSession>(
+      castor::tape::tapeFile::WriteSession(d, volInfo, 0, true, false)));
     ASSERT_EQ(ws->m_compressionEnabled, true);
     ASSERT_EQ(ws->m_vid.compare(label), 0);
     ASSERT_EQ(ws->isCorrupted(), false);
     {
       std::unique_ptr<castor::tape::tapeFile::WriteFile> wf;
-      ASSERT_NO_THROW(wf.reset(new castor::tape::tapeFile::WriteFile(ws, fileToMigrate, block_size)));
-      wf->write(testString.c_str(),testString.size());      
+      ASSERT_NO_THROW(wf = std::make_unique<castor::tape::tapeFile::WriteFile>(
+        ws.get(), fileToMigrate, block_size));
+      wf->write(testString.c_str(),testString.size());
       wf->close();
     }
-    delete ws;
     castor::tape::tapeFile::ReadSession *rs;
     rs = new castor::tape::tapeFile::ReadSession(d, volInfo, false);
     {
diff --git a/tapeserver/castor/tape/tapeserver/file/Structures.hpp b/tapeserver/castor/tape/tapeserver/file/Structures.hpp
index 008f1d474373720874b6d97263ca9eefa67d98b1..033015c590881dceefe94490d2c0101a94d62460 100644
--- a/tapeserver/castor/tape/tapeserver/file/Structures.hpp
+++ b/tapeserver/castor/tape/tapeserver/file/Structures.hpp
@@ -482,6 +482,7 @@ namespace tape {
      * c = century (blank=19; 0=20; 1=21; etc.) 
      * yy= year (00-99) ddd = day (001-366)
      */
+    #pragma GCC diagnostic ignored "-Wformat-overflow"
     inline void setDate(char(& t)[6]) {
       time_t current_time;
       struct tm localTime;
diff --git a/tapeserver/castor/tape/tapeserver/file/StructuresTest.cpp b/tapeserver/castor/tape/tapeserver/file/StructuresTest.cpp
index af1079ad305ed6198eeb8cfa941d82f8f491bae1..ffcfd60ec23b2e743fd71563e721f04042cd6e9c 100644
--- a/tapeserver/castor/tape/tapeserver/file/StructuresTest.cpp
+++ b/tapeserver/castor/tape/tapeserver/file/StructuresTest.cpp
@@ -20,11 +20,11 @@
 #include <gmock/gmock-cardinalities.h>
 
 namespace unitTests {
-  
+
   class testVOL1: public castor::tape::tapeFile::VOL1 {
   public:
     void backdoorSetLBPMethodString(const std::string & LBPString) {
-      ::strncpy(m_LBPMethod, LBPString.c_str(), sizeof(m_LBPMethod));
+      strcpy(m_LBPMethod, LBPString.c_str());
     }
   };
 
@@ -68,14 +68,14 @@ namespace unitTests {
     vol1Label.backdoorSetLBPMethodString("XY");
     ASSERT_THROW(vol1Label.getLBPMethod(), cta::exception::Exception);
   }
-  
+
   class testVOL1withCRC: public castor::tape::tapeFile::VOL1withCrc {
   public:
     void backdoorSetLBPMethodString(const std::string & LBPString) {
-      ::strncpy(m_LBPMethod, LBPString.c_str(), sizeof(m_LBPMethod));
+      strcpy(m_LBPMethod, LBPString.c_str());
     }
   };
-  
+
   TEST(castor_tape_AULFile, VOL1WithCRC) {
     typedef castor::tape::SCSI::logicBlockProtectionMethod LBPM;
     testVOL1withCRC vol1LabelWithCRC;
diff --git a/tapeserver/castor/tape/tapeserver/system/CMakeLists.txt b/tapeserver/castor/tape/tapeserver/system/CMakeLists.txt
index d7f5c9acde755744d0453e89bd62d36b15f1e227..5741def78a7c3a3300dded0b4b0f12e4b0c0793b 100644
--- a/tapeserver/castor/tape/tapeserver/system/CMakeLists.txt
+++ b/tapeserver/castor/tape/tapeserver/system/CMakeLists.txt
@@ -21,9 +21,3 @@ set_property(SOURCE Wrapper.cpp
   APPEND PROPERTY COMPILE_FLAGS -fno-strict-aliasing
 )
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  if(GCC_VERSION_GE_4_8_0)
-    set_property(SOURCE Wrapper.cpp
-      PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-  endif(GCC_VERSION_GE_4_8_0)
-endif(CMAKE_COMPILER_IS_GNUCC)
diff --git a/tapeserver/castor/tape/tapeserver/system/FileWrappers.cpp b/tapeserver/castor/tape/tapeserver/system/FileWrappers.cpp
index 56d1f93023600a8dab7301ce56685d7b5db88d89..8e13f7659d188d282aea278418293b695e329f21 100644
--- a/tapeserver/castor/tape/tapeserver/system/FileWrappers.cpp
+++ b/tapeserver/castor/tape/tapeserver/system/FileWrappers.cpp
@@ -761,34 +761,35 @@ int System::stIBM3592DeviceFile::logSenseDriveReadBackwardErrorsPage(sg_io_hdr_t
 
 int System::stIBM3592DeviceFile::logSensePerformanceCharacteristicsPage(sg_io_hdr_t * sgio_h) {
   SCSI::Structures::logSenseCDB_t* cdb = (SCSI::Structures::logSenseCDB_t*) (sgio_h->cmdp);
-  unsigned char *output;
+  unsigned char output_80[] = {
+    0x77, 0x80, 0x00, 0x1e, 0x00, 0x00, 0x60, 0x01, 0x50, 0x00, 0x01, 0x60, 0x01, 0x50, 0x00, 0x10, // 0x00
+    0x60, 0x01, 0x01, 0x00, 0x11, 0x60, 0x01, 0x50, 0x00, 0x12, 0x60, 0x01, 0x50, 0x00, 0x1a, 0x60, // 0x10
+    0x01, 0x50  // 0x20
+  };
+  unsigned char output_91[] = {
+    0x77, 0x91, 0x00, 0xd0, 0x01, 0x02, 0x60, 0x04, 0x00, 0x00, 0x05, 0x59, 0x02, 0x02, 0x60, 0x04, //0x00
+    0x00, 0x00, 0x10, 0x4b, 0x03, 0x02, 0x60, 0x04, 0x00, 0x11, 0x34, 0x7d, 0x03, 0xd0, 0x60, 0x04, //0x10
+    0x00, 0x60, 0x1a, 0xd3, 0x04, 0x02, 0x60, 0x04, 0x00, 0x0f, 0x7c, 0x0b, 0x04, 0xd0, 0x60, 0x04, //0x20
+    0x00, 0x62, 0xf3, 0x75, 0x05, 0x02, 0x60, 0x04, 0x00, 0x02, 0xb1, 0x68, 0x05, 0xd4, 0x60, 0x04, //0x30
+    0x00, 0x00, 0x05, 0x1b, 0x06, 0x02, 0x60, 0x04, 0x00, 0x20, 0x49, 0x13, 0x07, 0x02, 0x60, 0x04, //0x40
+    0x00, 0x06, 0xa7, 0xe9, 0x08, 0x02, 0x60, 0x04, 0x00, 0x00, 0x72, 0xcf, 0x09, 0x02, 0x60, 0x04, //0x50
+    0x00, 0x00, 0x00, 0x00, 0x0a, 0x02, 0x60, 0x04, 0x00, 0x00, 0x00, 0x2a, 0x0c, 0x02, 0x60, 0x04, //0x60
+    0x00, 0x4d, 0xcb, 0x5c, 0x0c, 0x0e, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x12, 0x60, 0x04, //0x70
+    0x00, 0x4d, 0xcb, 0x5c, 0x0c, 0x1e, 0x60, 0x04, 0x00, 0x00, 0x07, 0x03, 0x0c, 0x22, 0x60, 0x04, //0x80
+    0x00, 0x00, 0x00, 0x00, 0x0c, 0x2e, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa2, 0x60, 0x04, //0x90
+    0x00, 0x00, 0x22, 0x39, 0x0c, 0xae, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x14, 0x60, 0x04, //0xa0
+    0x00, 0x02, 0x23, 0xac, 0x0d, 0x24, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0xa4, 0x60, 0x04, //0xb0
+    0x00, 0x00, 0x00, 0x00, 0x0d, 0xf0, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0xf1, 0x60, 0x04, //0xc0
+    0x00, 0x00, 0x00, 0x00 //0xd0
+  };
+
+  unsigned char *output = 0;
   unsigned int output_size = 0;
   if(cdb->subPageCode == 0x80 || cdb->subPageCode == 0x40) {
-    unsigned char output_80[] = {
-      0x77, 0x80, 0x00, 0x1e, 0x00, 0x00, 0x60, 0x01, 0x50, 0x00, 0x01, 0x60, 0x01, 0x50, 0x00, 0x10, // 0x00
-      0x60, 0x01, 0x01, 0x00, 0x11, 0x60, 0x01, 0x50, 0x00, 0x12, 0x60, 0x01, 0x50, 0x00, 0x1a, 0x60, // 0x10
-      0x01, 0x50  // 0x20
-    };
     output = output_80;
     output_size = sizeof(output_80);
   }
   else if(cdb->subPageCode == 0x91 || cdb->subPageCode == 0x51) { ;
-    unsigned char output_91[] = {
-           0x77, 0x91, 0x00, 0xd0, 0x01, 0x02, 0x60, 0x04, 0x00, 0x00, 0x05, 0x59, 0x02, 0x02, 0x60, 0x04, //0x00
-           0x00, 0x00, 0x10, 0x4b, 0x03, 0x02, 0x60, 0x04, 0x00, 0x11, 0x34, 0x7d, 0x03, 0xd0, 0x60, 0x04, //0x10
-           0x00, 0x60, 0x1a, 0xd3, 0x04, 0x02, 0x60, 0x04, 0x00, 0x0f, 0x7c, 0x0b, 0x04, 0xd0, 0x60, 0x04, //0x20
-           0x00, 0x62, 0xf3, 0x75, 0x05, 0x02, 0x60, 0x04, 0x00, 0x02, 0xb1, 0x68, 0x05, 0xd4, 0x60, 0x04, //0x30
-           0x00, 0x00, 0x05, 0x1b, 0x06, 0x02, 0x60, 0x04, 0x00, 0x20, 0x49, 0x13, 0x07, 0x02, 0x60, 0x04, //0x40
-           0x00, 0x06, 0xa7, 0xe9, 0x08, 0x02, 0x60, 0x04, 0x00, 0x00, 0x72, 0xcf, 0x09, 0x02, 0x60, 0x04, //0x50
-           0x00, 0x00, 0x00, 0x00, 0x0a, 0x02, 0x60, 0x04, 0x00, 0x00, 0x00, 0x2a, 0x0c, 0x02, 0x60, 0x04, //0x60
-           0x00, 0x4d, 0xcb, 0x5c, 0x0c, 0x0e, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x12, 0x60, 0x04, //0x70
-           0x00, 0x4d, 0xcb, 0x5c, 0x0c, 0x1e, 0x60, 0x04, 0x00, 0x00, 0x07, 0x03, 0x0c, 0x22, 0x60, 0x04, //0x80
-           0x00, 0x00, 0x00, 0x00, 0x0c, 0x2e, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0c, 0xa2, 0x60, 0x04, //0x90
-           0x00, 0x00, 0x22, 0x39, 0x0c, 0xae, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0x14, 0x60, 0x04, //0xa0
-           0x00, 0x02, 0x23, 0xac, 0x0d, 0x24, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0xa4, 0x60, 0x04, //0xb0
-           0x00, 0x00, 0x00, 0x00, 0x0d, 0xf0, 0x60, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0d, 0xf1, 0x60, 0x04, //0xc0
-           0x00, 0x00, 0x00, 0x00 //0xd0
-    };
     output = output_91;
     output_size = sizeof(output_91);
   }
diff --git a/tapeserver/daemon/CMakeLists.txt b/tapeserver/daemon/CMakeLists.txt
index f16180106ca478bf0cdded6ece5125cfbc3e2307..c6a6a42bd2b04449be058a45881e24e552597679 100644
--- a/tapeserver/daemon/CMakeLists.txt
+++ b/tapeserver/daemon/CMakeLists.txt
@@ -39,16 +39,6 @@ add_library(ctatapedaemon
   TpconfigLine.cpp
   Tpconfig.cpp)
 
-if(CMAKE_COMPILER_IS_GNUCC)
-  if(GCC_VERSION_GE_4_8_0)
-    foreach(CTATAPESERVERDAEMON_LIBRARY_SRC
-      DriveHandler.cpp)
-      set_property(SOURCE ${CTATAPESERVERDAEMON_LIBRARY_SRC}
-        PROPERTY COMPILE_FLAGS " -Wno-unused-local-typedefs")
-    endforeach(CTATAPESERVERDAEMON_LIBRARY_SRC)
-  endif(GCC_VERSION_GE_4_8_0)
-endif(CMAKE_COMPILER_IS_GNUCC)
-
 target_link_libraries(ctatapedaemon
   ctatapesession
   ctaTapeServerDaemon
diff --git a/tapeserver/tapelabel/TapeLabelCmdLineArgsTest.cpp b/tapeserver/tapelabel/TapeLabelCmdLineArgsTest.cpp
index f254bbfff41d58801fbc343c062b74ffd2f92843..796e5cdfdb99ef476ad7e1958c0cef0f41fd91c9 100644
--- a/tapeserver/tapelabel/TapeLabelCmdLineArgsTest.cpp
+++ b/tapeserver/tapelabel/TapeLabelCmdLineArgsTest.cpp
@@ -39,12 +39,12 @@ protected:
   /**
    * Creates a duplicate string using the new operator.
    */
-  char *dupString(const char *str) {
-    const size_t len = strlen(str);
-    char *duplicate = new char[len+1];
-    strncpy(duplicate, str, len);
-    duplicate[len] = '\0';
-    return duplicate;
+  char *dupString(const std::string &str) {
+    const int len = str.size();
+    char *copy = new char[len + 1];
+    std::copy(str.begin(), str.end(), copy);
+    copy[len] = '\0';
+    return copy;
   }
 
   virtual void SetUp() {
@@ -290,7 +290,7 @@ TEST_F(cta_tapeserver_tapelabel_TapeLabelCmdLineArgsTest, oldVid_missed) {
   args->argv[2] = dupString("VID001");
   args->argv[3] = dupString("-o");
   args->argv[4] = nullptr;
-  
+
   ASSERT_THROW(TapeLabelCmdLineArgs cmdLine(args->argc, args->argv),
     cta::exception::CommandLineNotParsed);
 }
diff --git a/xroot_plugins/XrdCtaStream.hpp b/xroot_plugins/XrdCtaStream.hpp
index 6ef3e7fd651f58f662470e4960daefe06e78940b..8cd6dd18abb8653ada47bc3eb99472e19c417cbf 100644
--- a/xroot_plugins/XrdCtaStream.hpp
+++ b/xroot_plugins/XrdCtaStream.hpp
@@ -65,7 +65,7 @@ public:
   virtual Buffer *GetBuff(XrdSsiErrInfo &eInfo, int &dlen, bool &last) override {
     XrdSsiPb::Log::Msg(XrdSsiPb::Log::DEBUG, LOG_SUFFIX, "GetBuff(): XrdSsi buffer fill request (", dlen, " bytes)");
 
-    XrdSsiPb::OStreamBuffer<Data> *streambuf;
+    std::unique_ptr<XrdSsiPb::OStreamBuffer<Data>> streambuf;
 
     try {
       if(isDone()) {
@@ -74,31 +74,28 @@ public:
         return nullptr;
       }
 
-      streambuf = new XrdSsiPb::OStreamBuffer<Data>(dlen);
+      streambuf = std::make_unique<XrdSsiPb::OStreamBuffer<Data>>(dlen);
 
-      dlen = fillBuffer(streambuf);
+      dlen = fillBuffer(streambuf.get());
 
       XrdSsiPb::Log::Msg(XrdSsiPb::Log::DEBUG, LOG_SUFFIX, "GetBuff(): Returning buffer with ", dlen, " bytes of data.");
     } catch(cta::exception::Exception &ex) {
       std::ostringstream errMsg;
       errMsg << __FUNCTION__ << " failed: Caught CTA exception: " << ex.what();
       eInfo.Set(errMsg.str().c_str(), ECANCELED);
-      delete streambuf;
       return nullptr;
     } catch(std::exception &ex) {
       std::ostringstream errMsg;
       errMsg << __FUNCTION__ << " failed: " << ex.what();
       eInfo.Set(errMsg.str().c_str(), ECANCELED);
-      delete streambuf;
       return nullptr;
     } catch(...) {
       std::ostringstream errMsg;
       errMsg << __FUNCTION__ << " failed: Caught an unknown exception";
       eInfo.Set(errMsg.str().c_str(), ECANCELED);
-      delete streambuf;
       return nullptr;
     }
-    return streambuf;
+    return streambuf.release();
   }
 
 private: