On 08/23/2010 03:26 PM, Denys Vlasenko wrote:
diff -x '*.po' -d -urpN abrt.4/inc/abrtlib.h
abrt.5/inc/abrtlib.h
--- abrt.4/inc/abrtlib.h 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/inc/abrtlib.h 2010-08-23 14:57:07.822400254 +0200
@@ -62,10 +62,13 @@ int vdprintf(int d, const char *format,
#include "abrt_types.h"
#include "xfuncs.h"
#include "logging.h"
+#include "read_write.h"
char* skip_whitespace(const char *s);
char* skip_non_whitespace(const char *s);
+char *concat_path_file(const char *path, const char *filename);
+char *append_to_malloced_string(char *mstr, const char *append);
#ifdef __cplusplus
@@ -87,7 +90,6 @@ int xatoi(const char *numstr);
* dies if input is not in [0, INT_MAX] range. Also will reject '-0' etc */
int xatoi_u(const char *numstr);
-#include "read_write.h"
/* copyfd_XX print read/write errors and return -1 if they occur */
enum {
@@ -217,13 +219,4 @@ static inline std::string ssprintf(const
return res;
}
-static inline std::string concat_path_file(const char *path, const char *filename)
-{
- char *lc;
-
- while (*filename == '/')
- filename++;
- lc = last_char_is(path, '/');
- return ssprintf("%s%s%s", path, (lc==NULL ? "/" : ""),
filename);
-}
#endif
diff -x '*.po' -d -urpN abrt.4/lib/plugins/CCpp.cpp abrt.5/lib/plugins/CCpp.cpp
--- abrt.4/lib/plugins/CCpp.cpp 2010-08-18 13:41:27.000000000 +0200
+++ abrt.5/lib/plugins/CCpp.cpp 2010-08-23 15:10:30.000000000 +0200
@@ -460,12 +460,15 @@ static double get_dir_size(const char *d
{
if (dot_or_dotdot(ep->d_name))
continue;
- string dname = concat_path_file(dirname, ep->d_name);
- if (lstat(dname.c_str(),&stats) != 0)
+ char *dname = concat_path_file(dirname, ep->d_name);
+ if (lstat(dname,&stats) != 0)
+ {
+ free(dname);
continue;
+ }
if (S_ISDIR(stats.st_mode))
{
- double sz = get_dir_size(dname.c_str(), worst_file, maxsz);
+ double sz = get_dir_size(dname, worst_file, maxsz);
size += sz;
}
else if (S_ISREG(stats.st_mode))
@@ -489,6 +492,7 @@ static double get_dir_size(const char *d
}
}
}
+ free(dname);
}
closedir(dp);
return size;
@@ -583,7 +587,6 @@ string CAnalyzerCCpp::GetGlobalUUID(cons
// This whole block should be deleted for Fedora 14.
log(_("Getting global universal unique identification..."));
- string backtrace_path = concat_path_file(pDebugDumpDir, FILENAME_BACKTRACE);
string executable;
string package;
string uid_str;
@@ -597,13 +600,14 @@ string CAnalyzerCCpp::GetGlobalUUID(cons
{
/* Run abrt-backtrace to get independent backtrace suitable
to UUID calculation. */
+ char *backtrace_path = concat_path_file(pDebugDumpDir, FILENAME_BACKTRACE);
char *args[7];
args[0] = (char*)"abrt-backtrace";
args[1] = (char*)"--single-thread";
args[2] = (char*)"--remove-exit-handlers";
args[3] = (char*)"--frame-depth=5";
args[4] = (char*)"--remove-noncrash-frames";
- args[5] = (char*)backtrace_path.c_str();
+ args[5] = backtrace_path;
args[6] = NULL;
int pipeout[2];
@@ -633,6 +637,7 @@ string CAnalyzerCCpp::GetGlobalUUID(cons
exit(1);
}
+ free(backtrace_path);
close(pipeout[1]); /* write side of the pipe */
/* Read the result from abrt-backtrace. */
diff -x '*.po' -d -urpN abrt.4/lib/plugins/FileTransfer.cpp
abrt.5/lib/plugins/FileTransfer.cpp
--- abrt.4/lib/plugins/FileTransfer.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/plugins/FileTransfer.cpp 2010-08-23 13:13:13.555150331 +0200
@@ -55,7 +55,7 @@ void CFileTransfer::SendFile(const char
update_client(_("Sending archive %s to %s"), pFilename, pURL);
- string wholeURL = concat_path_file(pURL, strrchr(pFilename, '/') ? :
pFilename);
+ char *whole_url = concat_path_file(pURL, strrchr(pFilename, '/') ? :
pFilename);
int count = m_nRetryCount;
while (1)
@@ -63,6 +63,7 @@ void CFileTransfer::SendFile(const char
FILE *f = fopen(pFilename, "r");
if (!f)
{
+ free(whole_url);
throw CABRTException(EXCEP_PLUGIN, "Can't open archive file
'%s'", pFilename);
}
@@ -73,7 +74,7 @@ void CFileTransfer::SendFile(const char
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* specify target */
- curl_easy_setopt(curl, CURLOPT_URL, wholeURL.c_str());
+ curl_easy_setopt(curl, CURLOPT_URL, whole_url);
/* FILE handle: passed to the default callback, it will fread() it */
curl_easy_setopt(curl, CURLOPT_READDATA, f);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)buf.st_size);
@@ -88,6 +89,7 @@ void CFileTransfer::SendFile(const char
/* retry the upload if not succesful, wait a bit before next try */
sleep(m_nRetryDelay);
}
+ free(whole_url);
}
static void create_tar(const char *archive_name, const char *directory)
diff -x '*.po' -d -urpN abrt.4/lib/plugins/ReportUploader.cpp
abrt.5/lib/plugins/ReportUploader.cpp
--- abrt.4/lib/plugins/ReportUploader.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/plugins/ReportUploader.cpp 2010-08-23 15:12:12.000000000 +0200
@@ -101,7 +101,7 @@ void CReportUploader::SendFile(const cha
update_client(_("Sending archive %s to %s"), pFilename, pURL);
const char *base = (strrchr(pFilename, '/') ? : pFilename-1) + 1;
- string wholeURL = concat_path_file(pURL, base);
+ char *whole_url = concat_path_file(pURL, base);
int count = retry_count;
int result;
while (1)
@@ -109,6 +109,7 @@ void CReportUploader::SendFile(const cha
FILE* f = fopen(pFilename, "r");
if (!f)
{
+ free(whole_url);
throw CABRTException(EXCEP_PLUGIN, "Can't open archive file
'%s'", pFilename);
}
struct stat buf;
@@ -117,7 +118,7 @@ void CReportUploader::SendFile(const cha
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
/* specify target */
- curl_easy_setopt(curl, CURLOPT_URL, wholeURL.c_str());
+ curl_easy_setopt(curl, CURLOPT_URL, whole_url);
curl_easy_setopt(curl, CURLOPT_READDATA, f);
curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, (curl_off_t)buf.st_size);
/* everything is done here; result 0 means success */
@@ -134,6 +135,7 @@ void CReportUploader::SendFile(const cha
/* retry the upload if not succesful, wait a bit before next try */
sleep(retry_delay);
}
+ free(whole_url);
if (count<= 0&& result != 0)
{
@@ -144,12 +146,15 @@ void CReportUploader::SendFile(const cha
static void write_str_to_file(const char *str, const char *path, const char *fname)
{
- string ofile_name = concat_path_file(path, fname);
- FILE *ofile = fopen(ofile_name.c_str(), "w");
+ char *ofile_name = concat_path_file(path, fname);
+ FILE *ofile = fopen(ofile_name, "w");
if (!ofile)
{
- throw CABRTException(EXCEP_PLUGIN, "Can't open '%s'",
ofile_name.c_str());
+ CABRTException e(EXCEP_PLUGIN, "Can't open '%s'",
ofile_name);
+ free(ofile_name);
+ throw e;
}
+ free(ofile_name);
fputs(str, ofile);
fclose(ofile);
}
@@ -212,11 +217,13 @@ string CReportUploader::Report(const map
{
throw CABRTException(EXCEP_PLUGIN, "Can't mkdir a temporary directory
in /tmp");
}
- string tmptar_name = concat_path_file(tmpdir_name, file_name.c_str());
- if (mkdir(tmptar_name.c_str(), 0700))
+ char *tmptar_name = concat_path_file(tmpdir_name, file_name.c_str());
+ if (mkdir(tmptar_name, 0700))
{
- throw CABRTException(EXCEP_PLUGIN, "Can't mkdir '%s'",
tmptar_name.c_str());
+ CABRTException e(EXCEP_PLUGIN, "Can't mkdir '%s'",
tmptar_name);
+ free(tmptar_name);
+ throw e;
}
// Copy each entry into the tarball root.
@@ -230,36 +237,39 @@ string CReportUploader::Report(const map
const char *content = it->second[CD_CONTENT].c_str();
if (it->second[CD_TYPE] == CD_TXT)
{
- write_str_to_file(content, tmptar_name.c_str(), it->first.c_str());
+ write_str_to_file(content, tmptar_name, it->first.c_str());
}
else if (it->second[CD_TYPE] == CD_BIN)
{
- string ofile_name = concat_path_file(tmptar_name.c_str(),
it->first.c_str());
- if (copy_file(content, ofile_name.c_str(), 0644)< 0)
+ char *ofile_name = concat_path_file(tmptar_name, it->first.c_str());
+ if (copy_file(content, ofile_name, 0644)< 0)
{
- throw CABRTException(EXCEP_PLUGIN,
+ CABRTException e(EXCEP_PLUGIN,
"Can't copy '%s' to '%s'",
- content,
- ofile_name.c_str()
+ content, ofile_name
);
+ free(tmptar_name);
+ free(ofile_name);
+ throw e;
}
+ free(ofile_name);
}
}
// add ticket_name and customer name to tarball
if (have_ticket_name)
{
- write_str_to_file(ticket_name.c_str(), tmptar_name.c_str(),
"TICKET");
+ write_str_to_file(ticket_name.c_str(), tmptar_name, "TICKET");
}
if (customer_name != "")
{
- write_str_to_file(customer_name.c_str(), tmptar_name.c_str(),
"CUSTOMER");
+ write_str_to_file(customer_name.c_str(), tmptar_name, "CUSTOMER");
}
// Create the compressed tarball
string outfile_basename = file_name + ".tar.gz";
I'm proposing instead of
struct strbuf *outfile_name = strbuf_new();
- string outfile_name = concat_path_file(tmpdir_name,
outfile_basename.c_str());
- string cmd = ssprintf("tar -C %s --create --gzip --file=%s %s",
tmpdir_name, outfile_name.c_str(), file_name.c_str());
+ char *outfile_name = concat_path_file(tmpdir_name, outfile_basename.c_str());
strbuf_append_str(outfile_name, concat_path_file(tmpdir_name,
outfile_basename.c_str()));
+ string cmd = ssprintf("tar -C %s --create --gzip --file=%s
%s", tmpdir_name, outfile_name, file_name.c_str());
string cmd =
ssprintf("tar -C %s --create --gzip --file=%s %s", tmpdir_name,
outfile_name->buf, file_name.c_str());
RunCommand(cmd.c_str());
// encrypt if requested
@@ -270,9 +280,9 @@ string CReportUploader::Report(const map
string infile_name = outfile_name;
outfile_basename += ".aes";
- outfile_name += ".aes";
+ outfile_name = append_to_malloced_string(outfile_name, ".aes");
strbuf_append_str(outfile_name, ".aes")
- cmd = ssprintf("openssl aes-128-cbc -in %s -out %s -pass stdin",
infile_name.c_str(), outfile_name.c_str());
+ cmd = ssprintf("openssl aes-128-cbc -in %s -out %s -pass stdin",
infile_name.c_str(), outfile_name);
WriteCommand(cmd.c_str(), key.c_str());
}
@@ -284,11 +294,11 @@ string CReportUploader::Report(const map
if (do_upload)
{
// FIXME: SendFile isn't working sometime (scp)
- SendFile(upload_url.c_str(), outfile_name.c_str(), retry_count, retry_delay);
+ SendFile(upload_url.c_str(), outfile_name, retry_count, retry_delay);
SendFile(upload_url.c_str(), buf_outfile_name->buf, retry_count, retry_delay);
}
else
{
- cmd = ssprintf("cp %s /tmp/", outfile_name.c_str());
+ cmd = ssprintf("cp %s /tmp/", outfile_name);
cmd =
ssprintf("cp %s /tmp/", outfile_name->buf);
RunCommand(cmd.c_str());
}
@@ -343,6 +353,9 @@ string CReportUploader::Report(const map
cmd = ssprintf("rm -rf %s", tmpdir_name);
RunCommand(cmd.c_str());
+ free(tmptar_name);
+ free(outfile_name);
strbuf_free(outfile_name);
+
return msg;
}
diff -x '*.po' -d -urpN abrt.4/lib/plugins/RHTSupport.cpp
abrt.5/lib/plugins/RHTSupport.cpp
--- abrt.4/lib/plugins/RHTSupport.cpp 2010-08-18 13:41:27.000000000 +0200
+++ abrt.5/lib/plugins/RHTSupport.cpp 2010-08-23 13:36:39.393150300 +0200
@@ -202,17 +202,19 @@ string CReporterRHticket::Report(const m
basename++;
else
basename = content;
- string xml_name = concat_path_file("content", basename);
+ char *xml_name = concat_path_file("content", basename);
reportfile_add_binding_from_namedfile(file,
/*on_disk_filename */ content,
/*binding_name */ it->first.c_str(),
- /*recorded_filename*/ xml_name.c_str(),
+ /*recorded_filename*/ xml_name,
/*binary */ 1);
- if (tar_append_file(tar, (char*)content, (char*)(xml_name.c_str())) !=
0)
+ if (tar_append_file(tar, (char*)content, xml_name) != 0)
{
retval = "can't create temporary file in
"LOCALSTATEDIR"/run/abrt";
+ free(xml_name);
goto ret;
}
+ free(xml_name);
}
}
}
diff -x '*.po' -d -urpN abrt.4/lib/plugins/SOSreport.cpp
abrt.5/lib/plugins/SOSreport.cpp
--- abrt.4/lib/plugins/SOSreport.cpp 2010-08-18 13:41:27.000000000 +0200
+++ abrt.5/lib/plugins/SOSreport.cpp 2010-08-23 13:35:26.512150980 +0200
@@ -123,42 +123,44 @@ void CActionSOSreport::Run(const char *p
throw CABRTException(EXCEP_PLUGIN, "Can't find filename in sosreport
output");
}
- string sosreport_dd_filename = concat_path_file(pActionDir,
"sosreport.tar");
+ char *sosreport_dd_filename = concat_path_file(pActionDir,
"sosreport.tar");
char *ext = strrchr(sosreport_filename, '.');
if (ext&& strcmp(ext, ".tar") != 0)
{
// Assuming it's .bz2, .gz or some such
- sosreport_dd_filename += ext;
+ sosreport_dd_filename = append_to_malloced_string(sosreport_dd_filename, ext);
}
+
CDebugDump dd;
if (!dd.Open(pActionDir))
{
VERB1 log(_("Unable to open debug dump '%s'"),
pDebugDumpDir);
+ free(sosreport_filename);
+ free(sosreport_dd_filename);
return;
}
//Not useful: dd.SaveText("sosreportoutput", output);
- off_t sz = copy_file(sosreport_filename, sosreport_dd_filename.c_str(), 0644);
+ off_t sz = copy_file(sosreport_filename, sosreport_dd_filename, 0644);
// don't want to leave sosreport-XXXX.tar.bz2 in /tmp
unlink(sosreport_filename);
// sosreport-XXXX.tar.bz2.md5 too
- unsigned len = strlen(sosreport_filename);
- sosreport_filename = (char*)xrealloc(sosreport_filename, len +
sizeof(".md5")-1 + 1);
- strcpy(sosreport_filename + len, ".md5");
+ sosreport_filename = append_to_malloced_string(sosreport_filename,
".md5");
unlink(sosreport_filename);
+ dd.Close();
if (sz< 0)
{
- dd.Close();
CABRTException e(EXCEP_PLUGIN,
"Can't copy '%s' to '%s'",
- sosreport_filename,
- sosreport_dd_filename.c_str()
+ sosreport_filename, sosreport_dd_filename
);
free(sosreport_filename);
+ free(sosreport_dd_filename);
throw e;
}
free(sosreport_filename);
+ free(sosreport_dd_filename);
#endif
}
ditto with strbuf
diff -x '*.po' -d -urpN abrt.4/lib/utils/abrt_rh_support.cpp
abrt.5/lib/utils/abrt_rh_support.cpp
--- abrt.4/lib/utils/abrt_rh_support.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/utils/abrt_rh_support.cpp 2010-08-23 14:45:27.304400549 +0200
@@ -190,8 +190,9 @@ reportfile_add_binding_from_namedfile(re
//<binding name=NAME fileName=FILENAME type=text/binary...
internal_reportfile_start_binding(file, binding_name, isbinary,
recorded_filename);
// ... href=content/NAME>
- string href_name = concat_path_file("content", binding_name);
- xxmlTextWriterWriteAttribute(file->writer, "href", href_name.c_str());
+ char *href_name = concat_path_file("content", binding_name);
+ xxmlTextWriterWriteAttribute(file->writer, "href", href_name);
+ free(href_name);
}
//
@@ -222,7 +223,7 @@ reportfile_free(reportfile_t* file)
char*
post_signature(const char* baseURL, bool ssl_verify, const char* signature)
{
- string URL = concat_path_file(baseURL, "/signatures");
+ char *URL = concat_path_file(baseURL, "/signatures");
abrt_post_state *state = new_abrt_post_state(0
+ ABRT_POST_WANT_HEADERS
@@ -230,7 +231,8 @@ post_signature(const char* baseURL, bool
+ ABRT_POST_WANT_ERROR_MSG
+ (ssl_verify ? ABRT_POST_WANT_SSL_VERIFY : 0)
);
- int http_resp_code = abrt_post_string(state, URL.c_str(),
"application/xml", signature);
+ int http_resp_code = abrt_post_string(state, URL, "application/xml",
signature);
+ free(URL);
char *retval;
const char *strata_msg;
@@ -369,7 +371,7 @@ send_report_to_new_case(const char* base
const char* component,
const char* report_file_name)
{
- string case_url = concat_path_file(baseURL, "/cases");
+ char *case_url = concat_path_file(baseURL, "/cases");
char *case_data = make_case_data(summary, description,
"Red Hat Enterprise Linux",
"6.0",
@@ -390,14 +392,16 @@ send_report_to_new_case(const char* base
);
case_state->username = username;
case_state->password = password;
- abrt_post_string(case_state, case_url.c_str(), "application/xml",
case_data);
+ abrt_post_string(case_state, case_url, "application/xml", case_data);
char *case_location = find_header_in_abrt_post_state(case_state,
"Location:");
switch (case_state->http_resp_code)
{
case 305: /* "305 Use Proxy" */
- if (++redirect_count< 10&& case_location) {
- case_url = case_location;
+ if (++redirect_count< 10&& case_location)
+ {
+ free(case_url);
+ case_url = xstrdup(case_location);
free_abrt_post_state(case_state);
goto redirect_case;
}
@@ -408,7 +412,7 @@ send_report_to_new_case(const char* base
* instead of returning html-encoded body, we show short concise message,
* and show offending URL (typos in which is a typical cause) */
retval = xasprintf("error in case creation, "
- "HTTP code: 404 (Not found), URL:'%s'",
case_url.c_str());
+ "HTTP code: 404 (Not found), URL:'%s'",
case_url);
break;
default:
@@ -431,7 +435,7 @@ send_report_to_new_case(const char* base
break;
case 200:
- case 201:
+ case 201: {
if (!case_location) {
/* Case Creation returned valid code, but no location */
retval = xasprintf("error in case creation: no Location URL, HTTP
code: %d",
@@ -439,7 +443,7 @@ send_report_to_new_case(const char* base
break;
}
- string atch_url = concat_path_file(case_location, "/attachments");
+ char *atch_url = concat_path_file(case_location, "/attachments");
abrt_post_state *atch_state;
redirect_attach:
atch_state = new_abrt_post_state(0
@@ -450,14 +454,16 @@ send_report_to_new_case(const char* base
);
atch_state->username = username;
atch_state->password = password;
- abrt_post_file_as_form(atch_state, atch_url.c_str(),
"application/binary", report_file_name);
+ abrt_post_file_as_form(atch_state, atch_url, "application/binary",
report_file_name);
char *atch_location = find_header_in_abrt_post_state(atch_state,
"Location:");
switch (atch_state->http_resp_code)
{
case 305: /* "305 Use Proxy" */
- if (++redirect_count< 10&& atch_location) {
- atch_url = atch_location;
+ if (++redirect_count< 10&& atch_location)
+ {
+ free(atch_url);
+ atch_url = xstrdup(atch_location);
free_abrt_post_state(atch_state);
goto redirect_attach;
}
@@ -503,11 +509,15 @@ send_report_to_new_case(const char* base
//}
retval = xasprintf("Case created: %s", /*body,*/ case_location);
} /* switch (attach HTTP code) */
+
free_abrt_post_state(atch_state);
+ free(atch_url);
+ } /* case 200/201 */
} /* switch (case HTTP code) */
free_abrt_post_state(case_state);
free(allocated);
+ free(case_url);
return retval;
}
diff -x '*.po' -d -urpN abrt.4/lib/utils/append_to_malloced_string.cpp
abrt.5/lib/utils/append_to_malloced_string.cpp
--- abrt.4/lib/utils/append_to_malloced_string.cpp 1970-01-01 01:00:00.000000000 +0100
+++ abrt.5/lib/utils/append_to_malloced_string.cpp 2010-08-23 15:00:27.535150194 +0200
@@ -0,0 +1,27 @@
+/*
+ Copyright (C) 2010 ABRT team
+ Copyright (C) 2010 RedHat Inc
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along
+ with this program; if not, write to the Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+#include "abrtlib.h"
+
+char *append_to_malloced_string(char *mstr, const char *append)
+{
+ unsigned mlen = strlen(mstr);
+ mstr = (char*) xrealloc(mstr, mlen + strlen(append) + 1);
+ strcpy(mstr + mlen, append);
+ return mstr;
+}
You don't need this if you use strbuf
diff -x '*.po' -d -urpN abrt.4/lib/utils/concat_path_file.cpp
abrt.5/lib/utils/concat_path_file.cpp
--- abrt.4/lib/utils/concat_path_file.cpp 1970-01-01 01:00:00.000000000 +0100
+++ abrt.5/lib/utils/concat_path_file.cpp 2010-08-23 15:07:47.000000000 +0200
@@ -0,0 +1,25 @@
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 2001 Erik Andersen
+ *
+ * Licensed under GPLv2 or later.
+ */
+
+/* Concatenate path and filename to new allocated buffer.
+ * Add '/' only as needed (no duplicate // are produced).
+ * If path is NULL, it is assumed to be "/".
+ * filename should not be NULL.
+ */
+
+#include "abrtlib.h"
+
+char *concat_path_file(const char *path, const char *filename)
+{
+ if (!path)
+ path = "";
+ const char *end = path + strlen(path);
+ while (*filename == '/')
+ filename++;
+ return xasprintf("%s%s%s", path, (end != path&& end[-1] !=
'/' ? "/" : ""), filename);
+}
Rename it to concat_patch_file.c
diff -x '*.po' -d -urpN abrt.4/lib/utils/DebugDump.cpp
abrt.5/lib/utils/DebugDump.cpp
--- abrt.4/lib/utils/DebugDump.cpp 2010-08-18 13:41:27.000000000 +0200
+++ abrt.5/lib/utils/DebugDump.cpp 2010-08-23 14:14:52.743150070 +0200
@@ -109,8 +109,10 @@ bool CDebugDump::Open(const char *pDir)
bool CDebugDump::Exist(const char* pPath)
{
- std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pPath);
- return ExistFileDir(fullPath.c_str());
+ char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pPath);
+ bool r = ExistFileDir(full_path);
+ free(full_path);
+ return r;
}
static bool GetAndSetLock(const char* pLockFile, const char* pPID)
@@ -362,17 +364,19 @@ static bool DeleteFileDir(const char *pD
{
if (dot_or_dotdot(dent->d_name))
continue;
- std::string fullPath = concat_path_file(pDir, dent->d_name);
- if (unlink(fullPath.c_str()) == -1)
+ char *full_path = concat_path_file(pDir, dent->d_name);
+ if (unlink(full_path) == -1)
{
if (errno != EISDIR)
{
closedir(dir);
- error_msg("Can't remove dir '%s'",
fullPath.c_str());
+ error_msg("Can't remove dir '%s'", full_path);
+ free(full_path);
return false;
}
- DeleteFileDir(fullPath.c_str());
+ DeleteFileDir(full_path);
}
+ free(full_path);
}
closedir(dir);
if (rmdir(pDir) == -1)
@@ -459,8 +463,9 @@ void CDebugDump::LoadText(const char* pN
if (!m_bOpened)
error_msg_and_die("DebugDump is not opened");
- std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName);
- LoadTextFile(fullPath.c_str(), pData);
+ char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pName);
+ LoadTextFile(full_path, pData);
+ free(full_path);
}
void CDebugDump::SaveText(const char* pName, const char* pData)
@@ -468,16 +473,18 @@ void CDebugDump::SaveText(const char* pN
if (!m_bOpened)
error_msg_and_die("DebugDump is not opened");
- std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName);
- SaveBinaryFile(fullPath.c_str(), pData, strlen(pData), m_uid, m_gid);
+ char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pName);
+ SaveBinaryFile(full_path, pData, strlen(pData), m_uid, m_gid);
+ free(full_path);
}
void CDebugDump::SaveBinary(const char* pName, const char* pData, unsigned pSize)
{
if (!m_bOpened)
error_msg_and_die("DebugDump is not opened");
- std::string fullPath = concat_path_file(m_sDebugDumpDir.c_str(), pName);
- SaveBinaryFile(fullPath.c_str(), pData, pSize, m_uid, m_gid);
+ char *full_path = concat_path_file(m_sDebugDumpDir.c_str(), pName);
+ SaveBinaryFile(full_path, pData, pSize, m_uid, m_gid);
+ free(full_path);
}
bool CDebugDump::InitGetNextFile()
diff -x '*.po' -d -urpN abrt.4/lib/utils/dirsize.cpp
abrt.5/lib/utils/dirsize.cpp
--- abrt.4/lib/utils/dirsize.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/utils/dirsize.cpp 2010-08-23 13:38:59.521400170 +0200
@@ -33,17 +33,21 @@ double get_dirsize(const char *pPath)
{
if (dot_or_dotdot(ep->d_name))
continue;
- string dname = concat_path_file(pPath, ep->d_name);
- if (lstat(dname.c_str(),&statbuf) != 0)
+ char *dname = concat_path_file(pPath, ep->d_name);
+ if (lstat(dname,&statbuf) != 0)
+ {
+ free(dname);
continue;
+ }
if (S_ISDIR(statbuf.st_mode))
{
- size += get_dirsize(dname.c_str());
+ size += get_dirsize(dname);
}
else if (S_ISREG(statbuf.st_mode))
{
size += statbuf.st_size;
}
+ free(dname);
}
closedir(dp);
return size;
@@ -66,12 +70,15 @@ double get_dirsize_find_largest_dir(
{
if (dot_or_dotdot(ep->d_name))
continue;
- string dname = concat_path_file(pPath, ep->d_name);
- if (lstat(dname.c_str(),&statbuf) != 0)
+ char *dname = concat_path_file(pPath, ep->d_name);
+ if (lstat(dname,&statbuf) != 0)
+ {
+ free(dname);
continue;
+ }
if (S_ISDIR(statbuf.st_mode))
{
- double sz = get_dirsize(dname.c_str());
+ double sz = get_dirsize(dname);
size += sz;
if (worst_dir&& (!excluded || strcmp(excluded, ep->d_name) !=
0))
@@ -94,6 +101,7 @@ double get_dirsize_find_largest_dir(
{
size += statbuf.st_size;
}
+ free(dname);
}
closedir(dp);
return size;
diff -x '*.po' -d -urpN abrt.4/lib/utils/hooklib.cpp
abrt.5/lib/utils/hooklib.cpp
--- abrt.4/lib/utils/hooklib.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/utils/hooklib.cpp 2010-08-23 13:37:27.584159722 +0200
@@ -127,7 +127,9 @@ void trim_debug_dumps(unsigned setting_M
if (dirsize / (1024*1024)< setting_MaxCrashReportsSize || worst_dir ==
"")
break;
log("size of '%s'>= %u MB, deleting '%s'",
DEBUG_DUMPS_DIR, setting_MaxCrashReportsSize, worst_dir.c_str());
- delete_debug_dump_dir(concat_path_file(DEBUG_DUMPS_DIR,
worst_dir.c_str()).c_str());
+ char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str());
+ delete_debug_dump_dir(d);
+ free(d);
worst_dir = "";
}
}
diff -x '*.po' -d -urpN abrt.4/lib/utils/Makefile.am
abrt.5/lib/utils/Makefile.am
--- abrt.4/lib/utils/Makefile.am 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/lib/utils/Makefile.am 2010-08-23 15:00:40.159400743 +0200
@@ -11,6 +11,8 @@ AM_YFLAGS = --verbose
libABRTUtils_la_SOURCES = \
xfuncs.c \
+ concat_path_file.cpp \
+ append_to_malloced_string.cpp \
encbase64.cpp \
read_write.c read_write.h \
logging.c logging.h \
diff -x '*.po' -d -urpN abrt.4/src/daemon/Daemon.cpp
abrt.5/src/daemon/Daemon.cpp
--- abrt.4/src/daemon/Daemon.cpp 2010-08-17 19:17:22.000000000 +0200
+++ abrt.5/src/daemon/Daemon.cpp 2010-08-23 15:15:56.000000000 +0200
@@ -293,9 +293,9 @@ static void FindNewDumps(const char* pPa
{
if (dot_or_dotdot(ep->d_name))
continue; /* skip "." and ".." */
- std::string dname = concat_path_file(pPath, ep->d_name);
+ char *dname = concat_path_file(pPath, ep->d_name);
struct stat stats;
- if (lstat(dname.c_str(),&stats) == 0)
+ if (lstat(dname,&stats) == 0)
{
if (S_ISDIR(stats.st_mode))
{
@@ -303,6 +303,7 @@ static void FindNewDumps(const char* pPa
dirs.push_back(dname);
}
}
+ free(dname);
}
closedir(dp);
@@ -511,23 +512,26 @@ static gboolean handle_inotify_cb(GIOCha
log("Size of '%s'>= %u MB, deleting '%s'",
DEBUG_DUMPS_DIR, g_settings_nMaxCrashReportsSize, worst_dir.c_str());
g_pCommLayer->QuotaExceed(_("The size of the report exceeded
the quota. Please check system's MaxCrashReportsSize value in abrt.conf."));
/* deletes both directory and DB record */
- DeleteDebugDump_by_dir(concat_path_file(DEBUG_DUMPS_DIR,
worst_dir.c_str()).c_str());
+ char *d = concat_path_file(DEBUG_DUMPS_DIR, worst_dir.c_str());
+ DeleteDebugDump_by_dir(d);
+ free(d);
worst_dir = "";
}
}
+ char *fullname = NULL;
try
{
- std::string fullname = concat_path_file(DEBUG_DUMPS_DIR, name);
+ fullname = concat_path_file(DEBUG_DUMPS_DIR, name);
/* Note: SaveDebugDump does not save crashinfo, it _fetches_ crashinfo */
map_crash_data_t crashinfo;
- mw_result_t res = SaveDebugDump(fullname.c_str(), crashinfo);
+ mw_result_t res = SaveDebugDump(fullname, crashinfo);
switch (res)
{
case MW_OK:
- log("New crash %s, processing", fullname.c_str());
+ log("New crash %s, processing", fullname);
/* Run automatic actions and reporters on it (if we have them
configured) */
- RunActionsAndReporters(fullname.c_str());
+ RunActionsAndReporters(fullname);
/* Fall through */
case MW_REPORTED: /* already reported dup */
@@ -537,9 +541,9 @@ static gboolean handle_inotify_cb(GIOCha
{
const char *first = get_crash_data_item_content(crashinfo,
CD_DUMPDIR).c_str();
log("Deleting crash %s (dup of %s), sending dbus
signal",
- strrchr(fullname.c_str(), '/') + 1,
+ strrchr(fullname, '/') + 1,
strrchr(first, '/') + 1);
- delete_debug_dump_dir(fullname.c_str());
+ delete_debug_dump_dir(fullname);
}
#define fullname fullname_should_not_be_used_here
@@ -597,20 +601,24 @@ static gboolean handle_inotify_cb(GIOCha
case MW_GPG_ERROR:
case MW_FILE_ERROR:
default:
- log("Corrupted or bad crash %s (res:%d), deleting",
fullname.c_str(), (int)res);
- delete_debug_dump_dir(fullname.c_str());
+ log("Corrupted or bad crash %s (res:%d), deleting",
fullname, (int)res);
+ delete_debug_dump_dir(fullname);
break;
}
}
catch (CABRTException& e)
{
+ free(fullname);
+ fullname = NULL;
error_msg("%s", e.what());
}
catch (...)
{
+ free(fullname);
free(buf);
throw;
}
+ free(fullname);
} /* while */
free(buf);
Rest seems ok to me.