@@ -237,6 +237,7 @@ intern_location(struct pf2_session *session, VALUE cme, int lineno)
237237 struct pf2_location_key key = { .cme = cme , .lineno = lineno };
238238 int absent ;
239239 khint_t k = pf2_location_table_put (session -> location_table , key , & absent );
240+ if (k == kh_end (session -> location_table )) { return (size_t )-1 ; }
240241 if (absent ) {
241242 kh_val (session -> location_table , k ) = kh_size (session -> location_table ) - 1 ;
242243 }
@@ -249,6 +250,7 @@ intern_stack(struct pf2_session *session, const size_t *frames, size_t depth)
249250 struct pf2_stack_key skey = { .frames = frames , .depth = depth };
250251 int absent ;
251252 khint_t k = pf2_stack_table_put (session -> stack_table , skey , & absent );
253+ if (k == kh_end (session -> stack_table )) { return (size_t )-1 ; }
252254 if (absent ) {
253255 size_t * copy = NULL ;
254256 if (depth > 0 ) {
@@ -270,6 +272,7 @@ intern_native_stack(struct pf2_session *session, const uintptr_t *frames, size_t
270272 struct pf2_native_stack_key skey = { .frames = frames , .depth = depth };
271273 int absent ;
272274 khint_t k = pf2_native_stack_table_put (session -> native_stack_table , skey , & absent );
275+ if (k == kh_end (session -> native_stack_table )) { return (size_t )-1 ; }
273276 if (absent ) {
274277 uintptr_t * copy = NULL ;
275278 if (depth > 0 ) {
@@ -292,6 +295,7 @@ insert_sample(struct pf2_session *session, const struct pf2_sample *sample)
292295 // Convert each frame to a location
293296 for (int i = 0 ; i < sample -> depth ; i ++ ) {
294297 frame_ids [i ] = intern_location (session , sample -> cmes [i ], sample -> linenos [i ]);
298+ if (frame_ids [i ] == (size_t )-1 ) { return false; }
295299 }
296300
297301 // Obtain stack_id for the array of locations
@@ -308,6 +312,7 @@ insert_sample(struct pf2_session *session, const struct pf2_sample *sample)
308312 .native_stack_id = native_stack_id
309313 };
310314 khint_t k = pf2_sample_table_put (session -> sample_table , ckey , & absent );
315+ if (k == kh_end (session -> sample_table )) { return false; }
311316 struct pf2_sample_stats * stats = & kh_val (session -> sample_table , k );
312317 if (absent ) {
313318 // This is the first time this stack was observed. Initialize stats.
0 commit comments