From 9e4907551c8c56efe149f07d7f8537008ba6904e Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Mon, 19 Jun 2017 10:02:39 +0100 Subject: [PATCH] dinitctl: clean up a TODO. --- src/dinitctl.cc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/dinitctl.cc b/src/dinitctl.cc index e8c5daa..d431ac8 100644 --- a/src/dinitctl.cc +++ b/src/dinitctl.cc @@ -454,16 +454,13 @@ static int startStopService(int socknum, const char *service_name, Command comma // a response. Returns 1 on failure (with error logged), 0 on success. static int issueLoadService(int socknum, const char *service_name) { - using namespace std; - // Build buffer; uint16_t sname_len = strlen(service_name); int bufsize = 3 + sname_len; int r; - { - // TODO: new: catch exception - unique_ptr ubuf(new char[bufsize]); + try { + std::unique_ptr ubuf(new char[bufsize]); auto buf = ubuf.get(); buf[0] = DINIT_CP_LOADSERVICE; @@ -472,6 +469,10 @@ static int issueLoadService(int socknum, const char *service_name) r = write_all(socknum, buf, bufsize); } + catch (std::bad_alloc &badalloc) { + std::cerr << "dinitctl: " << badalloc.what() << std::endl; + return 1; + } if (r == -1) { perror("dinitctl: write"); -- 2.25.1