Commit 7c529d2d5df1012cdbfef10683cbc0311c94722e
1 parent
da845351
removed unnecessary use of malloc
Showing
1 changed file
with
9 additions
and
10 deletions
openbr/plugins/gallery.cpp
| ... | ... | @@ -194,11 +194,11 @@ class utGallery : public BinaryGallery |
| 194 | 194 | Template readTemplate() |
| 195 | 195 | { |
| 196 | 196 | Template t; |
| 197 | - br_utemplate ut = (br_utemplate) malloc(sizeof(br_universal_template)); | |
| 198 | - if (gallery.read((char*)ut, sizeof(br_universal_template)) == sizeof(br_universal_template)) { | |
| 199 | - QByteArray data(ut->size, Qt::Uninitialized); | |
| 197 | + br_universal_template ut; | |
| 198 | + if (gallery.read((char*)&ut, sizeof(br_universal_template)) == sizeof(br_universal_template)) { | |
| 199 | + QByteArray data(ut.size, Qt::Uninitialized); | |
| 200 | 200 | char *dst = data.data(); |
| 201 | - qint64 bytesNeeded = ut->size; | |
| 201 | + qint64 bytesNeeded = ut.size; | |
| 202 | 202 | while (bytesNeeded > 0) { |
| 203 | 203 | qint64 bytesRead = gallery.read(dst, bytesNeeded); |
| 204 | 204 | if (bytesRead <= 0) |
| ... | ... | @@ -207,21 +207,20 @@ class utGallery : public BinaryGallery |
| 207 | 207 | dst += bytesRead; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - if (QCryptographicHash::hash(data, QCryptographicHash::Md5) != QByteArray((const char*)ut->templateID, 16)) | |
| 210 | + if (QCryptographicHash::hash(data, QCryptographicHash::Md5) != QByteArray((const char*)ut.templateID, 16)) | |
| 211 | 211 | qFatal("MD5 hash check failure!"); |
| 212 | 212 | |
| 213 | - if (ut->algorithmID == 5) { | |
| 213 | + if (ut.algorithmID == 5) { | |
| 214 | 214 | QDataStream stream(&data, QIODevice::ReadOnly); |
| 215 | 215 | stream >> t; |
| 216 | 216 | } else { |
| 217 | 217 | t.append(cv::Mat(1, data.size(), CV_8UC1, data.data()).clone() /* We don't want a shallow copy! */); |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - t.file.set("ImageID", QVariant(QByteArray((const char*)ut->imageID, 16).toHex())); | |
| 221 | - t.file.set("TemplateID", QVariant(QByteArray((const char*)ut->templateID, 16).toHex())); | |
| 222 | - t.file.set("AlgorithmID", ut->algorithmID); | |
| 220 | + t.file.set("ImageID", QVariant(QByteArray((const char*)ut.imageID, 16).toHex())); | |
| 221 | + t.file.set("TemplateID", QVariant(QByteArray((const char*)ut.templateID, 16).toHex())); | |
| 222 | + t.file.set("AlgorithmID", ut.algorithmID); | |
| 223 | 223 | } |
| 224 | - free(ut); | |
| 225 | 224 | return t; |
| 226 | 225 | } |
| 227 | 226 | ... | ... |