App crashes due to QNetworkReply
-
https://github.com/TruePadawan/Notepad--
I have a simple text-editor program I'm working on. It has a feature where you simply click on a button and the current Qt/C++ code gets pasted on pastebin.Previously it gets my pastebin API key from a txt file but thats trash so I made a basic proxy server and made it get the key from there, but now it crashes on exit. If I comment out the API key request process, it doesnt crash on exit.
header file - https://pastebin.com/CqGiZQVN
definition - https://pastebin.com/5ihnR5wVI think the problem has to do with QNetworkReply or because I ran the program on Win7 because someone else ran it on win10 and it didnt crash on exit. So any idea on what the problem could be?
-
@Padawan said in App crashes due to QNetworkReply:
So any idea on what the problem could be?
Please also provide a stack trace after the crash.
-
As the screenshot shows, you have a segfault here. Probably from accessing any invalid pointer.
You commented some lines?! Does it still crash when you run it like this?For example; I've noticed that you
deleteLater
yourapiData
, but there is also adelete apiData
in d'tor (commented but still there). -
@JoeCFD said in App crashes due to QNetworkReply:
especially on Windows.
This is wrong - you always have to initialize your variables...
-
@Christian-Ehrlicher On Linux the default value is nullptr. It is a good habit to initialize them with nullptr all the time.
-
@JoeCFD said in App crashes due to QNetworkReply:
On Linux the default value is nullptr.
No, it is not.
-
@Christian-Ehrlicher
double * aaa;
std::cout << "aaa=" << aaa << std::endl;
aaa=0 -
Just because it does print 0 here it does not mean it's correctly initialized - it's by accident because your stack where
aaa
points to is currently filled with zeros. A good memory analyzer like e.g. valgrind will tell you that you're accessing uninitialized data.See https://godbolt.org/z/9vsrva15a - myPtr is not initialized anywhere before usage.
-
@JoeCFD said in App crashes due to QNetworkReply:
double * aaa;
std::cout << "aaa=" << aaa << std::endl;
aaa=0This is the best way to create an application with random crashes!
Never use a uninitialized pointer.This is a very basic rule in C/C++.
-
@Christian-Ehrlicher You are right. I tried it in middle of my app and uninitialized pointers are dangled. My memory is getting worse. I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.
-
@JoeCFD
It's a C++ language thing, so not per-platform. What you may find, on any platform/compiler, is that there is a difference between what you find in uninitialized (stack) variables between debug versus release builds. Or that may apply to heap areas. It's all undefined :) -
@JoeCFD said in App crashes due to QNetworkReply:
I remember one of the differences between Linux and Windows is that variables on Linux have default values. I am wrong. But I do initialize all my pointers.
AFAIK, on Linux/GCC pointers are never initialized per default.
On Windows/MSVC, they are set to 0 in debug build, but not in release. -
@KroMignon said in App crashes due to QNetworkReply:
On Windows/MSVC, they are set to 0 in debug build, but not in release.
Wrong again - it's 0xCCCCCCCC or 0xCDCDCDCD
See https://en.wikipedia.org/wiki/Magic_number_(programming)#Debug_values -
@Christian-Ehrlicher said in App crashes due to QNetworkReply:
Wrong again - it's 0xCCCCCCCC or 0xCDCDCDCD
Yes, I was wrong... sorry, too fare away.
I mixed up pointer initialization and variable initialization!!