]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/commitdiff
trackfds.h: Fix realloc() in update_environment().
authorSimon Ruderich <simon@ruderich.org>
Tue, 4 Jun 2013 22:57:26 +0000 (00:57 +0200)
committerSimon Ruderich <simon@ruderich.org>
Tue, 4 Jun 2013 22:57:26 +0000 (00:57 +0200)
src/trackfds.h

index 3577fd6323cbaef8d30150f1737362bc7deff4f9..34f0b1d8db793fe8274b02ac52cd9df8abb38ad0 100644 (file)
@@ -161,7 +161,8 @@ static void update_environment(void) {
 static void tracked_fds_add(int fd) {
     if (tracked_fds_count >= tracked_fds_space) {
         size_t new_space = tracked_fds_space + TRACKFDS_REALLOC_STEP;
-        if (!realloc(tracked_fds, sizeof(*tracked_fds) * new_space)) {
+        int *tmp = realloc(tracked_fds, sizeof(*tracked_fds) * new_space);
+        if (!tmp) {
             /* We can do nothing, just ignore the error. We made sure not to
              * destroy our state, so the new descriptor is ignored without any
              * other consequences. */
@@ -171,6 +172,7 @@ static void tracked_fds_add(int fd) {
 #endif
             return;
         }
+        tracked_fds = tmp;
         tracked_fds_space = new_space;
     }