Skip to content

Instantly share code, notes, and snippets.

@b1tninja
Last active April 23, 2019 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b1tninja/445b480b6b4e0c910b3a9180e01ac8fc to your computer and use it in GitHub Desktop.
Save b1tninja/445b480b6b4e0c910b3a9180e01ac8fc to your computer and use it in GitHub Desktop.
powertop segfault
commit e0f684d20bf22126842a4d7d69a87be73135426b
gpg: Signature made Tue 23 Apr 2019 05:42:37 AM PDT
gpg: using RSA key F6CC1F4DF325EACBBE2532481F299543498470BA
gpg: issuer "justincapella@gmail.com"
gpg: Good signature from "Justin Capella <justincapella@gmail.com>" [ultimate]
Author: b1tninja <devnull@localhost>
Date: Tue Apr 23 05:42:37 2019 -0700
Call clear when unable to properly allocate the perf event
diff --git a/src/perf/perf.cpp b/src/perf/perf.cpp
index 9ed0ba8..93c938c 100644
--- a/src/perf/perf.cpp
+++ b/src/perf/perf.cpp
@@ -132,13 +132,16 @@ void perf_event::create_perf_event(char *eventname, int _cpu)
PROT_READ | PROT_WRITE, MAP_SHARED, perf_fd, 0);
if (perf_mmap == MAP_FAILED) {
fprintf(stderr, "failed to mmap with %d (%s)\n", errno, strerror(errno));
+ clear();
return;
}
ret = ioctl(perf_fd, PERF_EVENT_IOC_ENABLE, 0);
if (ret < 0) {
- fprintf(stderr, "failed to enable perf \n");
+ fprintf(stderr, "failed to enable perf\n");
+ clear();
+ return;
}
pc = (perf_event_mmap_page *)perf_mmap;
@b1tninja
Copy link
Author

For debugging reasons, figured it best to just check the other variables are not set-- instead of relying on the fd being negative by clearing many... may help with debugging, may reveal other locations making false assumptions based around perf_fd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment