Resource leak (RESOURCE_LEAK) in source/common/ubidi.c in function setParaRunsOnly()

Description

When we are allocating a memory dynamically , the allocated memory must be free in all condition in failure and in success also.in the function setParaRuns() in source/common/ubidi.c, There is a chance of leaking memory.The assigned memory to runsOnlyMemory may be leaked at cleanup3: section.

Patch for this bug.

diff -Naurp a/source/common/ubidi.c b/source/common/ubidi.c
— a/source/common/ubidi.c 2014-08-28 16:11:29.114707222 +0530
+++ b/source/common/ubidi.c 2014-08-29 14:20:43.317621887 +0530
@@ -2513,11 +2513,18 @@
setParaRunsOnly(UBiDi *pBiDi, const UCha
pBiDi->trailingWSStart=saveTrailingWSStart;
/* free memory for mapping table and visual text */
uprv_free(runsOnlyMemory);
+ runsOnlyMemory=NULL;
if(pBiDi->runCount>1) {
pBiDi->direction=UBIDI_MIXED;
}
cleanup3:

  • pBiDi->reorderingMode=UBIDI_REORDER_RUNS_ONLY;
    + if(runsOnlyMemory != NULL)

+ {

+ pBiDi->reorderingMode=UBIDI_REORDER_RUNS_ONLY;

+ uprv_free(runsOnlyMemory);

+ }
+ else
+ pBiDi->reorderingMode=UBIDI_REORDER_RUNS_ONLY;
}

/* ubidi_setPara ------------------------------------------------------------ */

Attachments

1
  • 30 Jun 2018, 11:32 PM

relates to

Activity

Show:

UnicodeBot June 30, 2018 at 11:32 PM

Trac Comment 3 by —2015-01-07T21:33:45.413Z

Fixed the potential memory leak issue, but slightly different from the patch provided in this ticket.

Fixed

Assignee

Reporter

Components

Priority

Fix versions

Created June 28, 2018 at 5:22 PM
Updated July 1, 2018 at 8:44 PM
Resolved July 1, 2018 at 8:44 PM