qstats icon indicating copy to clipboard operation
qstats copied to clipboard

qstats crashes with no input + Ctrl-D

Open merwok opened this issue 7 years ago • 14 comments

$ qstats
^D
*** Error in `qstats': double free or corruption (!prev): 0x000055a539c09010 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bfb)[0x7f160f3abbfb]
[etc]

merwok avatar Nov 19 '17 22:11 merwok

That's interesting!! I tried it and got:

♥ qstats
^D
Input too small for meaningful summary

tonyfischetti avatar Nov 21 '17 03:11 tonyfischetti

I'll try it on a Linux box now

tonyfischetti avatar Nov 21 '17 03:11 tonyfischetti

Haha I got Error allocating memory. Will be investigating

tonyfischetti avatar Nov 21 '17 03:11 tonyfischetti

Oh I’m on Debian testing x86_64 with glibc 2.24

merwok avatar Nov 21 '17 14:11 merwok

Nothing seems to happen on my freeBSD macine when qstats is started without any arguments or file.

jungle-boogie avatar Nov 21 '17 15:11 jungle-boogie

@jungle-boogie When you start up qstats like that, it interactively takes input (if it doesn't, please let me know) Just type in the numbers (pressing enter in between each one) and when you're done, press Control-D. Does that work? Sorry in advance if I misunderstood what you meant

tonyfischetti avatar Nov 22 '17 03:11 tonyfischetti

@tonyfischetti, Doing that works and I don't get a crash:

./qstats
1
2
5
2600
30
Min.     1
1st Qu.  1.5
Median   5
Mean     527.6
3rd Qu.  1315
Max.     2600
Range    2599
Std Dev. 1036.25
Sum      2638
Length   5

But without any input, I do see the error:

% ./qstats
Error allocating memory%

jungle-boogie avatar Nov 22 '17 15:11 jungle-boogie

@jungle-boogie Ok, cool! It's supposed to do the interactive thing :) I'm investigating the error with memory allocation today. I wonder why it doesn't happen with the gcc on my Mac 🤔 Maybe I'll try it with different libc s

tonyfischetti avatar Nov 22 '17 18:11 tonyfischetti

I can't replicate this :( If this is still an issue, can you let me know and I'll reopen the issue

tonyfischetti avatar Dec 31 '17 03:12 tonyfischetti

Changed title to clarify the steps to reproduce: no input followed by Ctrl-D (see original message).

merwok avatar Dec 31 '17 16:12 merwok

Haha no I mean, I can't reproduce the crash and backtrace when I do that. On all my systems, I either get

♥ qstats
^D
Input too small for meaningful summary

Or

♥ qstats
^D
Error allocating memory

No unhandled crash or backtrace

tonyfischetti avatar Jan 02 '18 22:01 tonyfischetti

Found out the Error allocating memory issue. Over in infuncs.c we have:

   /* resize to not waste memory */
    temp = realloc(build_array, size * sizeof(double));
    if(temp == NULL){
        free(build_array);
        fputs("Error allocating memory", stderr);
        exit(EXIT_FAILURE);
    }

If there's no input, size will equal 0. The result of allocating 0 is either a unique pointer or just NULL. On systems where this returns NULL, qstats thinks it's an allocation failure.

I'm guessing on @merwok's system, a unique pointer is returned, and somewhere along the line qstats tries writing to it, causing a memory error. The Input too small message happens too far down, after the data_array has already been accessed several times.

I'm guessing a fix would just be to exit early if size is 0.

refi64 avatar Jan 02 '18 23:01 refi64

Also note that my compiler warns about a handful of unused variables. Looking at these and the problem in the previous message may fix my crash!

merwok avatar Jan 02 '18 23:01 merwok

Cool! I'll get on this! Thanks for the investigation!

tonyfischetti avatar Jan 04 '18 00:01 tonyfischetti