]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - e2fsck/util.c
e2fsck: avoid mallinfo() if over 2GB allocated
[thirdparty/e2fsprogs.git] / e2fsck / util.c
index 6ac56dad6f67a1e93132cf47ecde22f4bd7133b9..d98b8e47be66ed5516fb2f1cae2dc427edb23d57 100644 (file)
@@ -420,9 +420,6 @@ void print_resource_track(e2fsck_t ctx, const char *desc,
 {
 #ifdef HAVE_GETRUSAGE
        struct rusage r;
-#endif
-#ifdef HAVE_MALLINFO
-       struct mallinfo malloc_info;
 #endif
        struct timeval time_end;
 
@@ -436,18 +433,21 @@ void print_resource_track(e2fsck_t ctx, const char *desc,
        if (desc)
                log_out(ctx, "%s: ", desc);
 
+#define kbytes(x)      (((unsigned long long)(x) + 1023) / 1024)
 #ifdef HAVE_MALLINFO
-#define kbytes(x)      (((unsigned long)(x) + 1023) / 1024)
-
-       malloc_info = mallinfo();
-       log_out(ctx, _("Memory used: %luk/%luk (%luk/%luk), "),
-               kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
-               kbytes(malloc_info.uordblks), kbytes(malloc_info.fordblks));
-#else
-       log_out(ctx, _("Memory used: %lu, "),
-               (unsigned long) (((char *) sbrk(0)) -
-                                ((char *) track->brk_start)));
+       /* don't use mallinfo() if over 2GB used, since it returns "int" */
+       if ((char *)sbrk(0) - (char *)track->brk_start < 2ULL << 30) {
+               struct mallinfo malloc_info = mallinfo();
+
+               log_out(ctx, _("Memory used: %lluk/%lluk (%lluk/%lluk), "),
+                       kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
+                       kbytes(malloc_info.uordblks),
+                       kbytes(malloc_info.fordblks));
+       } else
 #endif
+       log_out(ctx, _("Memory used: %lluk, "),
+               kbytes(((char *)sbrk(0)) - ((char *)track->brk_start)));
+
 #ifdef HAVE_GETRUSAGE
        getrusage(RUSAGE_SELF, &r);