summaryrefslogtreecommitdiffstats
path: root/kdeprint/cups
diff options
context:
space:
mode:
authorRoman Savochenko <rom_as@oscada.org>2013-01-05 02:51:08 +0100
committerSlávek Banko <slavek.banko@axis.cz>2013-01-05 02:57:18 +0100
commitbb2a1e349f302299e394ff86f27be3df41f08fb3 (patch)
tree98d22b1d3f6c14bceef37c26032109c68a43a00b /kdeprint/cups
parent34180e15ea386866402148e5f53c38cca99f82d5 (diff)
downloadtdelibs-bb2a1e349f302299e394ff86f27be3df41f08fb3.tar.gz
tdelibs-bb2a1e349f302299e394ff86f27be3df41f08fb3.zip
Fix memory leak in CUPS IPP processing
This resolves Bug 1369 (cherry picked from commit 5f99a2718025c4f2fbef86a450423a9c61e297f9)
Diffstat (limited to 'kdeprint/cups')
-rw-r--r--kdeprint/cups/ipprequest.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/kdeprint/cups/ipprequest.cpp b/kdeprint/cups/ipprequest.cpp
index 68294ecd8..3506ec384 100644
--- a/kdeprint/cups/ipprequest.cpp
+++ b/kdeprint/cups/ipprequest.cpp
@@ -21,6 +21,7 @@
#include "cupsinfos.h"
#include <stdlib.h>
+#include <string>
#include <cups/language.h>
#include <kdebug.h>
#include <kglobal.h>
@@ -227,14 +228,19 @@ void IppRequest::addStringList_p(int group, int type, const TQString& name, cons
{
if (!name.isEmpty())
{
- ipp_attribute_t *attr = ippAddStrings(request_,(ipp_tag_t)group,(ipp_tag_t)type,name.latin1(),(int)(values.count()),NULL,NULL);
- int i(0);
- for (TQStringList::ConstIterator it=values.begin(); it != values.end(); ++it, i++)
-#ifdef HAVE_CUPS_1_6
- ippSetString(request_, &attr, i, strdup((*it).local8Bit()));
-#else // HAVE_CUPS_1_6
- attr->values[i].string.text = strdup((*it).local8Bit());
-#endif // HAVE_CUPS_1_6
+ //> Values buffer and references offset prepare
+ const char *vlsRefs[values.count()];
+ std::string vlsBuf;
+ for(unsigned i_vl = 0; i_vl < values.count(); i_vl++)
+ {
+ vlsRefs[i_vl] = (const char*)vlsBuf.size();
+ vlsBuf += values[i_vl].local8Bit();
+ vlsBuf += (char)0;
+ }
+ //> References update to pointers
+ for(unsigned i_vl = 0; i_vl < values.count(); i_vl++)
+ vlsRefs[i_vl] = vlsBuf.data()+(intptr_t)vlsRefs[i_vl];
+ ippAddStrings(request_,(ipp_tag_t)group,(ipp_tag_t)type,name.latin1(),(int)(values.count()),NULL,(const char**)&vlsRefs);
}
}