![]() |
![]() |
![]() |
![]() |
![]() |
|
Now, however, you must also be sure that trade_pointers[limit]
contains a nonnull pointer before you try to access the string. The first
time analyze_trades is called, the trade_pointers array
contains null pointers, and you must not try to access a structure
variables via a null pointer. Accordingly, you must test for the
null pointer before deploying free.
...
if (! trade_pointers [limit]) {
free (trade_pointers[limit] -> description);
free (trade_pointers[limit]);
}
...
If your program fails to test for a null pointer, your program is likely to corrupt a memory location near zero, leading to a spectacular crash.