0

I am running splint on a piece of C code and it gave me the following statement:

jmptable.c:34:5: Implicitly only storage vm->jumptable (type struct
     jumptable_entry **) not released before assignment:
     vm->jumptable = (struct jumptable_entry **)calloc(vm->jumptable_size + 1,
     sizeof(struct jumptable_entry *))

  A memory leak has been detected. Only-qualified storage is not released
  before the last reference to it is lost. (Use -mustfreeonly to inhibit
  warning)

I understand that splint wants me to free the memory before allocating it with calloc but since this is in the very initialization of the application should I worry about it?

Edit: This is how the vm->jumptable is initialized

vm->jumptable = (struct jumptable_entry**) calloc(vm->jumptable_size + 1,
                                          sizeof(struct jumptable_entry*));
Ferenc Deak
  • 34,348
  • 17
  • 99
  • 167

1 Answers1

0

OK, this is the first assignment. But what is going to happen next assignment? You should add a check to free the memory if vm->jumptable is not null.

EDIT/Clarification: It is not obvious from the fragment of code you have included if the initialization of the structure is done in a method that can be called to change the specific pointer at any time. If it does, then the next time you will attempt to assign a value(thus changing the current value) a memory leak will occur. Making sure, in that method, that the allocated memory from the previous instance is freed, is essential.

So, you can only ignore the message if you are absolutely certain you are not going to reassign the value in your code using the same method you use for initialization.

ThunderGr
  • 2,297
  • 29
  • 20