Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: minor edits; reviewed

The tss_create() function creates a thread-specific storage pointed to pointer identified by a key. Threads can allocate thread-specific storage and associated it with a key by calling the tss_set() function. If not properly freed, this memory may be leaked. Ensure that thread-specific memory is freed.

...

In this compliant solution, each thread explicitly frees the thread-specific storage returned by the tss_get() function before completingterminating:

Code Block
bgColor#ccccff
langc
#include <threads.h>
#include <stdlib.h>
 
/* Global key to the thread-specific storage */
tss_t key;
 
int function(void *dummy) {
  if (add_data() != 0) {
    return -1;	/* Report error */
  }
  print_data();
  free(tss_get(key));
  return 0;
}

/* ... Other functions are unchanged */

int main(void) {
  /* ... */
  tss_delete(key);
  return 0;
}

...

Risk Assessment

Failing to destroy free thread-specific objects could lead to results in memory leaks and could result in a denial-of-service attack.

Rule

Severity

Likelihood

Remediation Cost

Priority

Level

CON30-C

Medium

Unlikely

Medium

P4

L3

...