Fixed #4647: nsc_context_free must not access possibly uninitialized fields.

This commit is contained in:
Armin Novak 2018-05-15 09:13:00 +02:00
parent c5b84db7e7
commit ae765430e9
2 changed files with 27 additions and 27 deletions

View File

@ -248,13 +248,13 @@ static BOOL nsc_context_initialize(NSC_CONTEXT* context, wStream* s)
return TRUE; return TRUE;
} }
static void nsc_profiler_print(NSC_CONTEXT* context) static void nsc_profiler_print(NSC_CONTEXT_PRIV* priv)
{ {
PROFILER_PRINT_HEADER PROFILER_PRINT_HEADER
PROFILER_PRINT(context->priv->prof_nsc_rle_decompress_data) PROFILER_PRINT(priv->prof_nsc_rle_decompress_data)
PROFILER_PRINT(context->priv->prof_nsc_decode) PROFILER_PRINT(priv->prof_nsc_decode)
PROFILER_PRINT(context->priv->prof_nsc_rle_compress_data) PROFILER_PRINT(priv->prof_nsc_rle_compress_data)
PROFILER_PRINT(context->priv->prof_nsc_encode) PROFILER_PRINT(priv->prof_nsc_encode)
PROFILER_PRINT_FOOTER PROFILER_PRINT_FOOTER
} }
@ -279,7 +279,7 @@ NSC_CONTEXT* nsc_context_new(void)
context->priv = (NSC_CONTEXT_PRIV*) calloc(1, sizeof(NSC_CONTEXT_PRIV)); context->priv = (NSC_CONTEXT_PRIV*) calloc(1, sizeof(NSC_CONTEXT_PRIV));
if (!context->priv) if (!context->priv)
goto error_priv; goto error;
context->priv->log = WLog_Get("com.freerdp.codec.nsc"); context->priv->log = WLog_Get("com.freerdp.codec.nsc");
WLog_OpenAppender(context->priv->log); WLog_OpenAppender(context->priv->log);
@ -289,7 +289,7 @@ NSC_CONTEXT* nsc_context_new(void)
context->priv->PlanePool = BufferPool_New(TRUE, 0, 16); context->priv->PlanePool = BufferPool_New(TRUE, 0, 16);
if (!context->priv->PlanePool) if (!context->priv->PlanePool)
goto error_PlanePool; goto error;
PROFILER_CREATE(context->priv->prof_nsc_rle_decompress_data, PROFILER_CREATE(context->priv->prof_nsc_rle_decompress_data,
"nsc_rle_decompress_data") "nsc_rle_decompress_data")
@ -303,34 +303,33 @@ NSC_CONTEXT* nsc_context_new(void)
/* init optimized methods */ /* init optimized methods */
NSC_INIT_SIMD(context); NSC_INIT_SIMD(context);
return context; return context;
error_PlanePool: error:
free(context->priv); nsc_context_free(context);
error_priv:
free(context);
return NULL; return NULL;
} }
void nsc_context_free(NSC_CONTEXT* context) void nsc_context_free(NSC_CONTEXT* context)
{ {
int i; size_t i;
if (!context)
return;
if (context->priv)
{
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{
if (context->priv->PlaneBuffers[i])
{
free(context->priv->PlaneBuffers[i]); free(context->priv->PlaneBuffers[i]);
context->priv->PlaneBuffers[i] = NULL;
}
}
free(context->BitmapData);
BufferPool_Free(context->priv->PlanePool); BufferPool_Free(context->priv->PlanePool);
nsc_profiler_print(context); nsc_profiler_print(context->priv);
PROFILER_FREE(context->priv->prof_nsc_rle_decompress_data) PROFILER_FREE(context->priv->prof_nsc_rle_decompress_data)
PROFILER_FREE(context->priv->prof_nsc_decode) PROFILER_FREE(context->priv->prof_nsc_decode)
PROFILER_FREE(context->priv->prof_nsc_rle_compress_data) PROFILER_FREE(context->priv->prof_nsc_rle_compress_data)
PROFILER_FREE(context->priv->prof_nsc_encode) PROFILER_FREE(context->priv->prof_nsc_encode)
free(context->priv); free(context->priv);
}
free(context->BitmapData);
free(context); free(context);
} }

View File

@ -51,7 +51,9 @@ PROFILER* profiler_create(char* name)
void profiler_free(PROFILER* profiler) void profiler_free(PROFILER* profiler)
{ {
if (profiler)
stopwatch_free(profiler->stopwatch); stopwatch_free(profiler->stopwatch);
free(profiler); free(profiler);
} }
@ -76,7 +78,6 @@ void profiler_print(PROFILER* profiler)
{ {
double s = stopwatch_get_elapsed_time_in_seconds(profiler->stopwatch); double s = stopwatch_get_elapsed_time_in_seconds(profiler->stopwatch);
double avg = profiler->stopwatch->count == 0 ? 0 : s / profiler->stopwatch->count; double avg = profiler->stopwatch->count == 0 ? 0 : s / profiler->stopwatch->count;
WLog_INFO(TAG, "%-30s | %10u | %10.4fs | %8.6fs | %6.0f", WLog_INFO(TAG, "%-30s | %10u | %10.4fs | %8.6fs | %6.0f",
profiler->name, profiler->stopwatch->count, s, avg, profiler->stopwatch->count / s); profiler->name, profiler->stopwatch->count, s, avg, profiler->stopwatch->count / s);
} }