Initialize CLEANUP_* stack variables with NULL in various places.

Code like:

  CLEANUP_FREE char *buf;
  /* some code which might return early */
  buf = malloc (10);

is a potential bug because the free (*buf) might be called when buf is
an uninitialized pointer.  Initialize buf = NULL to avoid this.

Several of these are bugs, most are not bugs (because there is no
early return statement before the variable gets initialized).

However the compiler can elide the initialization, and even if it does
not the performance "penalty" is miniscule, and correctness is better.
This commit is contained in:
Richard W.M. Jones
2013-08-22 19:48:05 +01:00
parent fc2947b112
commit b1919066ca
14 changed files with 18 additions and 18 deletions

View File

@@ -280,7 +280,7 @@ do_internal_lxattrlist (const char *path, char *const *names)
for (k = 0; names[k] != NULL; ++k) {
void *newptr;
CLEANUP_FREE char *pathname;
CLEANUP_FREE char *pathname = NULL;
/* Be careful in this loop about which errors cause the whole call
* to abort, and which errors allow us to continue processing