Skip to content

Commit

Permalink
classify/adaptmatch: Fix memory leak
Browse files Browse the repository at this point in the history
Coverity report:

CID 1340280 (#1 of 1): Resource leak (RESOURCE_LEAK)
7. leaked_storage: Variable FloatFeatures going out of scope leaks the storage it points to.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
  • Loading branch information
stweil committed Oct 24, 2016
1 parent a351dae commit b1f03cb
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion classify/adaptmatch.cpp
Expand Up @@ -907,8 +907,10 @@ void Classify::AdaptToChar(TBLOB* Blob, CLASS_ID ClassId, int FontinfoId,
IClass = ClassForClassId(adaptive_templates->Templates, ClassId);

NumFeatures = GetAdaptiveFeatures(Blob, IntFeatures, &FloatFeatures);
if (NumFeatures <= 0)
if (NumFeatures <= 0) {
FreeFeatureSet(FloatFeatures);

This comment has been minimized.

Copy link
@rmtheis

rmtheis Nov 7, 2016

Contributor

@stweil I'm getting a crash here (when running on Android) with the message Invalid address passed to free: invalid page index. I'm planning to open an issue with steps to reproduce the problem.

Stack trace here: rmtheis/tess-two#180

This comment has been minimized.

Copy link
@stweil

stweil Nov 7, 2016

Author Contributor

I have seen the same kind of crash recently. Obviously GetAdaptiveFeatures sometimes allocates a feature set (that's why I added the call to FreeFeatureSet, but not always. If it does not allocate, it should set FloatFeatureSet to 0. I'll send a PR which fixes this.

return;
}

// Only match configs with the matching font.
BIT_VECTOR MatchingFontConfigs = NewBitVector(MAX_NUM_PROTOS);
Expand Down

0 comments on commit b1f03cb

Please sign in to comment.