Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qstats crashes with no input + Ctrl-D #7

Open
merwok opened this issue Nov 19, 2017 · 14 comments
Open

qstats crashes with no input + Ctrl-D #7

merwok opened this issue Nov 19, 2017 · 14 comments

Comments

@merwok
Copy link

merwok commented Nov 19, 2017

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

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

♥ qstats
^D
Input too small for meaningful summary

@tonyfischetti
Copy link
Owner

I'll try it on a Linux box now

@tonyfischetti
Copy link
Owner

Haha I got Error allocating memory. Will be investigating

@merwok
Copy link
Author

merwok commented Nov 21, 2017

Oh I’m on Debian testing x86_64 with glibc 2.24

@jungle-boogie
Copy link

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

@tonyfischetti
Copy link
Owner

@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

@jungle-boogie
Copy link

@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%

@tonyfischetti
Copy link
Owner

@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
Copy link
Owner

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

@merwok merwok changed the title Crash if there is no input qstats crashes with no input + Ctrl-D Dec 31, 2017
@merwok
Copy link
Author

merwok commented Dec 31, 2017

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

@tonyfischetti
Copy link
Owner

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

@refi64
Copy link

refi64 commented Jan 2, 2018

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.

@merwok
Copy link
Author

merwok commented Jan 2, 2018

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!

@tonyfischetti
Copy link
Owner

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

@tonyfischetti tonyfischetti reopened this Jan 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants