@@ -620,15 +620,15 @@ void cb_downloadStart(AuthServer_Private& client)
620
620
}
621
621
filename = filename.replace (" \\ " , " /" );
622
622
623
- DS::Stream* stream;
623
+ std::unique_ptr< DS::Stream> stream;
624
624
// Check to see if this is our special SDL file...
625
625
if (DS::Settings::SendDescriptorDb () && filename.ends_with (" .sdl" , ST::case_sensitivity_t ::case_insensitive)) {
626
- stream = new DS::BlobStream (s_minifiedSdl);
626
+ stream = std::make_unique< DS::BlobStream> (s_minifiedSdl);
627
627
} else {
628
628
filename = DS::Settings::AuthRoot () + filename;
629
- stream = new DS::FileStream ();
629
+ stream = std::make_unique< DS::FileStream> ();
630
630
try {
631
- static_cast <DS::FileStream*>(stream)->open (filename.c_str (), " rb" );
631
+ static_cast <DS::FileStream*>(stream. get () )->open (filename.c_str (), " rb" );
632
632
} catch (const DS::FileIOException& ex) {
633
633
ST::printf (stderr, " [Auth] Could not open file {}: {}\n [Auth] Requested by {}\n " ,
634
634
filename, ex.what (), DS::SockIpAddress (client.m_sock ));
@@ -637,7 +637,6 @@ void cb_downloadStart(AuthServer_Private& client)
637
637
client.m_buffer .write <uint32_t >(0 ); // Chunk offset
638
638
client.m_buffer .write <uint32_t >(0 ); // Data packet size
639
639
SEND_REPLY ();
640
- delete stream;
641
640
return ;
642
641
}
643
642
}
@@ -650,12 +649,11 @@ void cb_downloadStart(AuthServer_Private& client)
650
649
client.m_buffer .write <uint32_t >(CHUNK_SIZE);
651
650
uint8_t * data = client.m_buffer .allocate (CHUNK_SIZE);
652
651
stream->readBytes (data, CHUNK_SIZE);
653
- client.m_downloads [transId] = stream;
652
+ client.m_downloads [transId] = std::move ( stream) ;
654
653
} else {
655
654
client.m_buffer .write <uint32_t >(stream->size ());
656
655
uint8_t * data = client.m_buffer .allocate (stream->size ());
657
656
stream->readBytes (data, stream->size ());
658
- delete stream;
659
657
}
660
658
661
659
SEND_REPLY ();
@@ -688,7 +686,6 @@ void cb_downloadNext(AuthServer_Private& client)
688
686
client.m_buffer .write <uint32_t >(bytesLeft);
689
687
uint8_t * data = client.m_buffer .allocate (bytesLeft);
690
688
fi->second ->readBytes (data, bytesLeft);
691
- delete fi->second ;
692
689
client.m_downloads .erase (fi);
693
690
}
694
691
0 commit comments