Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Side by Side Diff: net/ftp/ftp_directory_listing_buffer.cc

Issue 355037: Coverity: Fix leaking UCharsetDetector in ftp code. (Closed)
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "net/ftp/ftp_directory_listing_buffer.h" 5 #include "net/ftp/ftp_directory_listing_buffer.h"
6 6
7 #include "base/i18n/icu_string_conversions.h" 7 #include "base/i18n/icu_string_conversions.h"
8 #include "base/stl_util-inl.h" 8 #include "base/stl_util-inl.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "net/ftp/ftp_directory_listing_parsers.h" 11 #include "net/ftp/ftp_directory_listing_parsers.h"
12 #include "unicode/ucsdet.h" 12 #include "unicode/ucsdet.h"
13 13
14 namespace { 14 namespace {
15 15
16 // A very simple-minded character encoding detection. 16 // A very simple-minded character encoding detection.
17 // TODO(jungshik): We can apply more heuristics here (e.g. using various hints 17 // TODO(jungshik): We can apply more heuristics here (e.g. using various hints
18 // like TLD, the UI language/default encoding of a client, etc). In that case, 18 // like TLD, the UI language/default encoding of a client, etc). In that case,
19 // this should be pulled out of here and moved somewhere in base because there 19 // this should be pulled out of here and moved somewhere in base because there
20 // can be other use cases. 20 // can be other use cases.
21 std::string DetectEncoding(const std::string& text) { 21 std::string DetectEncoding(const std::string& text) {
22 if (IsStringASCII(text)) 22 if (IsStringASCII(text))
23 return std::string(); 23 return std::string();
24 UErrorCode status = U_ZERO_ERROR; 24 UErrorCode status = U_ZERO_ERROR;
25 UCharsetDetector* detector = ucsdet_open(&status); 25 UCharsetDetector* detector = ucsdet_open(&status);
26 ucsdet_setText(detector, text.data(), static_cast<int32_t>(text.length()), 26 ucsdet_setText(detector, text.data(), static_cast<int32_t>(text.length()),
27 &status); 27 &status);
28 const UCharsetMatch* match = ucsdet_detect(detector, &status); 28 const UCharsetMatch* match = ucsdet_detect(detector, &status);
29 const char* encoding = ucsdet_getName(match, &status); 29 const char* encoding = ucsdet_getName(match, &status);
30 ucsdet_close(detector);
30 // Should we check the quality of the match? A rather arbitrary number is 31 // Should we check the quality of the match? A rather arbitrary number is
31 // assigned by ICU and it's hard to come up with a lower limit. 32 // assigned by ICU and it's hard to come up with a lower limit.
32 if (U_FAILURE(status)) 33 if (U_FAILURE(status))
33 return std::string(); 34 return std::string();
34 return encoding; 35 return encoding;
35 } 36 }
36 37
37 } // namespace 38 } // namespace
38 39
39 namespace net { 40 namespace net {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT; 132 return ERR_UNRECOGNIZED_FTP_DIRECTORY_LISTING_FORMAT;
132 if (parsers_.size() == 1) 133 if (parsers_.size() == 1)
133 current_parser_ = *parsers_.begin(); 134 current_parser_ = *parsers_.begin();
134 } 135 }
135 } 136 }
136 137
137 return OK; 138 return OK;
138 } 139 }
139 140
140 } // namespace net 141 } // namespace net
OLDNEW
« no previous file with comments | « net/data/ftp/dir-listing-ls-1-utf8.expected ('k') | net/ftp/ftp_directory_listing_buffer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698